日期:2014-05-20  浏览次数:20644 次

向各位高手请教java连结sql2005的连结字符串(不要jdbcodbc桥)
希望大家帮帮忙啊!

------解决方案--------------------
先顶下。关注学习中!!
------解决方案--------------------
跟任何一个数据库连JAVA一样,实例去网上找吧,基实关键是找到JDBC驱动的JAR包


------解决方案--------------------
MS SQL Server 2005的JDBC 驱动包 针对不同的平台不一样,请检查是for32位的还是for64位。
------解决方案--------------------
最新的驱动是 sqljdbc1.1 只有一个文件,与以前版本不太一样,下载后包里面有中文的帮助文档,其中有连接sqlserver2000和sqlserver2005的范例和不同的连接字符串,属性等。

Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver "); // 2005 版

JDBC 驱动程序处理“jdbc:sqlserver://”URL 前缀
------解决方案--------------------
我做了个小的演示类,请参考。
楼上说得对,驱动升级了。现在写法不一样,想要更多细节请直接访问msdn

package jdsTutorial;


import java.sql.*;

public class SQLT01 {

public static void main(String[] args) {

// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost\\SQLEXPRESS; " +
"user=db51;password=mssql ";

// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try {
// Establish the connection.
Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver ");
con = DriverManager.getConnection(connectionUrl);

// Create and execute an SQL statement that returns some data.
String SQL = "SELECT TOP 10 * FROM USR ";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);

// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString( "PARTICIPANT ") + " " + rs.getString( "PDMUSRPASSWD "));
}
}

// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}

}
------解决方案--------------------
关注