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

}
}
}

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

    原文作者:海中一神兽
    原文地址: https://www.cnblogs.com/haima1949/p/11624850.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞