当前位置: 技术问答>java相关
我怎么连不上我的sql server 2000?我给分!
来源: 互联网 发布时间:2017-03-12
本文导语: 我的机器系统是professional,下了一个Microsoft SQL Server 2000 Driver for JDBC。我又把:Program FilesMicrosoft SQL Server 2000 Driver for JDBClib下的所有JAR文件都加入了CLASSPATH里,为什么还不行呢?我的程序代码如下: import...
我的机器系统是professional,下了一个Microsoft SQL Server 2000 Driver for JDBC。我又把:Program FilesMicrosoft SQL Server 2000 Driver for JDBClib下的所有JAR文件都加入了CLASSPATH里,为什么还不行呢?我的程序代码如下:
import java.sql.*;
public class ConnectSqlserver {
public static void main(String args[]){
java.sql.Connection sqlConn;
java.sql.Statement sqlStmt;
java.sql.ResultSet sqlRst;
//regiester jdbc driver
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//connect to the database
sqlConn=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.30:1433;DatabaseName=pubs","sa","");
//create the driver handle
sqlStmt=sqlConn.createStatement();
//excute sql
sqlRst=sqlStmt.executeQuery("select title_id,title,type from titles");
while(sqlRst.next()){
System.out.print(sqlRst.getString(1)+" ");
System.out.print(sqlRst.getString(2)+" ");
System.out.println(sqlRst.getString(3));
}
} catch (InstantiationException e) {
System.out.print(e);
} catch (IllegalAccessException e) {
System.out.print(e);
} catch (ClassNotFoundException e) {
System.out.print(e);
} catch (SQLException e) {
System.out.print(e);
}
}
}
错误如下:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket
import java.sql.*;
public class ConnectSqlserver {
public static void main(String args[]){
java.sql.Connection sqlConn;
java.sql.Statement sqlStmt;
java.sql.ResultSet sqlRst;
//regiester jdbc driver
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//connect to the database
sqlConn=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.30:1433;DatabaseName=pubs","sa","");
//create the driver handle
sqlStmt=sqlConn.createStatement();
//excute sql
sqlRst=sqlStmt.executeQuery("select title_id,title,type from titles");
while(sqlRst.next()){
System.out.print(sqlRst.getString(1)+" ");
System.out.print(sqlRst.getString(2)+" ");
System.out.println(sqlRst.getString(3));
}
} catch (InstantiationException e) {
System.out.print(e);
} catch (IllegalAccessException e) {
System.out.print(e);
} catch (ClassNotFoundException e) {
System.out.print(e);
} catch (SQLException e) {
System.out.print(e);
}
}
}
错误如下:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket
|
你用的是什么引擎,是tomcat么?
如果是:
请将MsSql JDBC三个驱动文件*.jar解开呈文件夹形式放入Tomcat的Classes目录下
如果是:
请将MsSql JDBC三个驱动文件*.jar解开呈文件夹形式放入Tomcat的Classes目录下