java当中JDBC当中请给出一个sql server的helloworld例子
[学习笔记]
1.sql server的helloworld例子:
import java.sql.*;
public class JdbcHelloSqlServer {
public static void main(String[] args) {
String dbUrl= "jdbc:jtds:sqlserver://localhost:1433/Northwind";String user = "sa";String password = "1234";
// String dbUrl="jdbc:mysql://localhost:3306/test"; String user = "root";String password = "1234";
String createString;
Statement stmt;
createString = "select * from orders";
try {
/*this method attempts to locate, load,
and link the class or interface. The specified class loader is
used to load the class or interface. If the parameter loader is
null, the class is loaded through the bootstrap class loader.
about soundBlaster driver?when you talk to the microphone, it can
record into the computer and save as a file. your sound is
transfered into 01 signal and save as a file. all these are done by driver.
the same thing, using DB? you also need driver.
*/
Class.forName("net.sourceforge.jtds.jdbc.Driver");
// Class.forName("com.mysql.jdbc.Driver");
/* When the method
getConnection is called, the DriverManager will attempt to
locate a suitable driver from amongst those loaded at initialization
*/
Connection con = DriverManager.getConnection(dbUrl, user, password);
System.out.println("Connection is ok");
/* Statement object is a workspace to create SQL queries, execute them, and retrieve any results that are returned.
tube has track,vehicle is on the track for coal. vehicle is only suitable for this track , not for any other track.
*/
stmt = con.createStatement();
// stmt.execute(createString);
/* Resultset object contains the table produced by the SQL query
*/
ResultSet rs = stmt.executeQuery(createString);
System.out.println("qixybefore");
//获得元数据
//获得元数据
ResultSetMetaData meta = rs.getMetaData();
for (int i = 1; i <= meta.getColumnCount(); i++) {
if (meta.getColumnType(i) == java.sql.Types.INTEGER) { // if it is CHAR
System.out.println("Types.INTEGER is " +i +" " + meta.getColumnName(i)); // display the name
}
System.out.println(meta.getColumnName(i)); //字段名称
}
System.out.println("qixylater");
/*boolean next() throws SQLException Moves the cursor down one row from its current position. A ResultSet cursor is initially
positioned before the first row; the first call to the method next makes the first row the current row; the second call makes
the second row the current row, and so on. Returns:true if the new current row is valid; false if there are no more rows */
while (rs.next()) {
文章转载自原文:https://blog.csdn.net/qq_44594249/article/details/100764762
java当中JDBC当中请给出一个sql server的helloworld例子的更多相关文章
- java当中JDBC当中请给出一个sql server的stored procedure例子
3.sql server的stored procedure例子: import java.sql.*;public class StoredProc0 {public static void main ...
- java当中JDBC当中请给出一个sql server的dataSource的helloworld例子
[学习笔记] 4. sql server的dataSource的helloworld: import java.sql.*;import javax.sql.*;import net.sourcef ...
- 请给出一个Scala RDD的HelloWorld例子
[学习笔记]package comimport org.apache.spark.rdd.RDDimport org.apache.spark.SparkConfimport org.apache.s ...
- java当中JDBC当中请给出一个Oracle DataSource and SingleTon例子
[学习笔记] 6.Oracle DataSource and SingleTon: import oracle.jdbc.pool.OracleDataSource;import java.sql.C ...
- java当中JDBC当中请给出一个SQLServer DataSource and SingleTon例子
[学习笔记] 5.SQLServer DataSource and SingleTon: import net.sourceforge.jtds.jdbcx.*;import java.sql.*;i ...
- 已知一个函数rand7()能够生成1-7的随机数,请给出一个函数rand10(),该函数能够生成1-10的随机数。
题目: 已知一个函数rand7()能够生成1-7的随机数,请给出一个函数,该函数能够生成1-10的随机数. 思路: 假如已知一个函数能够生成1-49的随机数,那么如何以此生成1-10的随机数呢? 解法 ...
- 请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件。
请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件. <a href=”mailto: zhangsan@d-heaven.com”>发邮件</ ...
- 使用java以及jdbc不使用第三方库执行sql文件脚本
使用java以及jdbc不使用第三方库执行sql文件脚本 2017年02月15日 15:51:45 阅读数:660 使用java执行sql脚本的方法 解析sql脚本,删除不必要的注释和空行 将语句按分 ...
- 如何使用OPENQUERY访问另一个SQL Server
原文:如何使用OPENQUERY访问另一个SQL Server 在项目中,经常会遇到一个数据库访问另一个数据库,[CNVFERPDB]为服务器名,[CE3]为库名 SELECT Dtl.* FROM ...
随机推荐
- SpringCloud:Ribbon负载均衡
1.概述 Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端 负载均衡的工具. 简单的说,Ribbon是Netflix发布的开源项目,主要功能是提供客 ...
- redis-migrate-tool
一.简介 redis-migrate-tool是在redis之间迁移数据的一个方便且有用的工具.他会已服务方式不断同步两边的数据.等到合适时间,中断redis读写,对比双方数据,再替换redis地址即 ...
- Xtrabackup--备份mysql
Xtrabackup介绍 Xtrabackup是由percona开源的免费数据库热备份软件,它能对InnoDB数据库和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁): ...
- SpringBoot 配置Druid:不显示SQL监控 —(*) property for user to setup
题外话: SpringBoot整合Druid 请查看https://www.cnblogs.com/JealousGirl/p/druid.html Druid登录后数据源页面.SQL监控等不显示数据 ...
- elasticsearch type类型创建时注意项目,最新的elasticsearch已经不建议一个索引下多个type
https://www.elastic.co/guide/cn/elasticsearch/guide/current/mapping.html如果有两个不同的类型,每个类型都有同名的字段,但映射不同 ...
- 纯JavaScript开发飞机大战项目
开发工具: HBuilder 编程语言:JavaScript 其他技术:Html + Css 项目截图: 视频: 源代码: 在线观看地址: (暂无) 百度网盘下载地址: 请加QQ群:915 ...
- python使用ThreadPoolExecutor每秒并发5个
import time from concurrent.futures import ThreadPoolExecutor from functools import partial from log ...
- IDEA_2019.2的安装与个人配置(Windows)
1. 下载 官方下载网站:https://www.jetbrains.com/idea/download/ IDEA是支持多平台的开发工具,分为Windows.Mac和Linux三个平台,这里就只拿W ...
- Momentum Contrast for Unsupervised Visual Representation Learning (MoCo)
Momentum Contrast for Unsupervised Visual Representation Learning 一.Methods Previously Proposed 1. E ...
- SuperWebSocket实现服务端和WebSocket4Net实现客户端
SuperWebSocket实现服务端和WebSocket4Net实现客户端具体实现如下: SuperWebSocket实现服务端 注:本作者是基于vs2019 enterprise版本,所有项目均为 ...