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

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){

}
}
}

result is:
There are 23 records in authors table.

版权保护原文出处:http://www.mark-to-win.com/JavaBeginner/JavaBeginner10_web.html#sqlserverdataSourcehelloworld

猜你喜欢

转载自blog.csdn.net/mark_to_win/article/details/89288809