当前位置:Gxlcms > 数据库问题 > java当中JDBC当中请给出一个sql server的dataSource的helloworld例子

java当中JDBC当中请给出一个sql server的dataSource的helloworld例子

时间:2021-07-01 10:21:17 帮助过:6人阅读

4. sql server的dataSource的helloworld:

import java.sql.*;
import javax.sql.*;
import net.sourceforge.jtds.jdbcx.*;

public class SimpleDataSource{
public static void main(String[] args){
try{
JtdsDataSource ds = new JtdsDataSource();
ds.setServerName("localhost");
ds.setDatabaseName("pubs");
ds.setUser("sa");
ds.setPassword("");

Connection con = ds.getConnection();
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("select count(*) from authors");
if(rs.next())
System.out.println("There are " + rs.getInt(1) + " records in authors table.");
}catch(Exception e){

}
}
}

文章转载自原文:https://blog.csdn.net/qq_43650923/article/details/100742896

java当中JDBC当中请给出一个sql server的dataSource的helloworld例子

标签:connect   host   public   rom   creates   int   system   学习笔记   font   

人气教程排行