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

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

}
}
}
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
result is:
There are 23 records in authors table.