public static void main(String[] args) throws ClassNotFoundException {
String JDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL数据库引擎
String connectDB="jdbc:sqlserver://127.0.0.1:1433 ;DatabaseName=Enterprise" ;
try{
Class.forName(JDriver);//加载数据库引擎,返回给定字符串名的类
System.out.println("加载数据库引擎成功");
}
catch(Exception e){
System.out.println("加载数据库引擎失败");
}
try{
Connection con=DriverManager.getConnection(connectDB,"sa","199193");//连接数据库对象
System.out.println("连接数据库成功");
Statement stmt=con.createStatement();//创建SQL命令对象
ResultSet rs=stmt.executeQuery("SELECT * FROM CMSCB");//返回SQL语句查询结果集(集合)
while(rs.next()){
System.out.println(rs.getObject("CB002"));
}
int i= rs.getConcurrency();
System.out.println(i);
con.close();
stmt.close();
}
catch(Exception e){
System.out.print("连接数据库失败");
System.out.print(e);
}
}