java与sql2005直连 的问题

来源:百度知道 编辑:UC知道 时间:2024/09/25 18:57:10
java 直连 2000的 SQL 需要 3个 什么 jar驱动。
但我记得 与05直连的时候 只需要 在该项目上 右键 选择Properties 然后java Build Path 选项右侧的Libraries 导入一个msssqlserver.jar的包 就可以

下面是代码
import java.sql.*;
public class NewsFirstTitleDB1 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con=null;
Statement statement=null;
try{
String strSql="insert into FirstLevelTitle values(1,'网管','军事',getdate())";
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(ClassNotFoundException e){
System.out.println("无法找到驱动类");
}
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=news","sa","sasasa");
statement=con.createStatement();
statement.executeUpdate(strSql);
}catch(SQLException

SQL Server 2000

String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=sample";

而SQL Server 2005 中加载驱动和URL的语句则为

String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=sample";

写成这样
private static String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String URL="jdbc:sqlserver://localhost:1433;databasename=news";
private static String USER="sa";
private static String PWD="sasasa";
static{
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConn(){
Connection conn =null;
try {