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

时间:2021-07-18 02:39:32

 [学习笔记]

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