当前位置: 技术问答>java相关
请问如何有JDBC连SQLSERVER数据库。谢谢。
来源: 互联网 发布时间:2015-05-23
本文导语: 请问如何有JDBC连SQLSERVER数据库。谢谢。 | /**address: SQL Server的连接参数*/ String address = "jdbc:microsoft:sqlserver://192.168.7.6:1433"; /***user: 数据库用户名*/ String user="sa"; /**passwd: 用户密...
请问如何有JDBC连SQLSERVER数据库。谢谢。
|
/**address: SQL Server的连接参数*/
String address = "jdbc:microsoft:sqlserver://192.168.7.6:1433";
/***user: 数据库用户名*/
String user="sa";
/**passwd: 用户密码*/
String passwd="";
/*数据库名*/
String database = "DMCADSQL";
DatabaseMetaData conMD = null;
java.sql.Statement stmt = null;
Connection con = null;
ResultSet sqlRst = null;
// try
// {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(address,user,passwd);
conMD = con.getMetaData();
con.setCatalog(database);
stmt = con.createStatement();
// }catch(Exception fs) {
// out.print("Connection ERROR
");
// }
// out.print("Connection
");
try
{
stmt=con.createStatement();
sqlRst = stmt.executeQuery("select drawing_code,version,file_name from drawing");
out.print("stmt OK");
}catch(Exception gr)
{
out.print("stmt ERROR");
}
String address = "jdbc:microsoft:sqlserver://192.168.7.6:1433";
/***user: 数据库用户名*/
String user="sa";
/**passwd: 用户密码*/
String passwd="";
/*数据库名*/
String database = "DMCADSQL";
DatabaseMetaData conMD = null;
java.sql.Statement stmt = null;
Connection con = null;
ResultSet sqlRst = null;
// try
// {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(address,user,passwd);
conMD = con.getMetaData();
con.setCatalog(database);
stmt = con.createStatement();
// }catch(Exception fs) {
// out.print("Connection ERROR
");
// }
// out.print("Connection
");
try
{
stmt=con.createStatement();
sqlRst = stmt.executeQuery("select drawing_code,version,file_name from drawing");
out.print("stmt OK");
}catch(Exception gr)
{
out.print("stmt ERROR");
}
|
微软站点JDBCforMSSqlServer下载地址=>|http://download.microsoft.com/download/SQLSVR2000/jdbc/2000/NT45XP/EN-US/setup.exe