怎么正确连接sql server 2000?????
package cn.wzb;
import java.sql.*;
import java.util.Vector;
public class TestJdbcsqlServer {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("实例化成功 is ok!!");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=factory","sa","sa");
System.out.println("the connection is ok!!");
Vector<String> fieldNames = new Vector<String>();
DatabaseMetaData metaData = conn.getMetaData();
rs = metaData.getColumns(null, null, "employee", null);
while(rs.next()) {
fieldNames.addElement(rs.getString(4) + "\t\t|");
}
System.out.print("Table employee:\n|");
for(int i=0;i<fieldNames.size();i++) {
System.out.print(fieldNames.elementAt(i));
}
System.out.println();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from employee order by id asc");
while(rs.next()) {
System.out.print("|");
for(int i=1;i<=fieldNames.size();i++) {
System.out.print(rs.getString(i) + "\t|");
}
System.out.println();
}
}
catch(ClassNotFoundException e) {
System.out.println("com.microsoft.jdbc.sqlserver.SQLServerDriver Is Not Found!!");
e.printStackTrace();
}
catch(SQLException e) {
System.out.println("SQLException: " + e.getMessage());
System.out.println("SQLSata: " + e.getSQLState());
System.out.println("VendorError: " + e.getErrorCode());
e.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
}
catch(SQLException e) {
e.printStackTrace();
}
catch(Exception e ) {
e.printStackTrace();
}
}
}
}
为什么老是有异常 ,连接不成功?我是DB新手,异常如下:
实例化成功 is ok!!
SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
SQLSata: 08001
VendorError: 0
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at cn.wzb.TestJdbcsqlServer.main(TestJdbcsqlServer.java:17)
请指点。
import java.sql.*;
import java.util.Vector;
public class TestJdbcsqlServer {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println("实例化成功 is ok!!");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=factory","sa","sa");
System.out.println("the connection is ok!!");
Vector<String> fieldNames = new Vector<String>();
DatabaseMetaData metaData = conn.getMetaData();
rs = metaData.getColumns(null, null, "employee", null);
while(rs.next()) {
fieldNames.addElement(rs.getString(4) + "\t\t|");
}
System.out.print("Table employee:\n|");
for(int i=0;i<fieldNames.size();i++) {
System.out.print(fieldNames.elementAt(i));
}
System.out.println();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from employee order by id asc");
while(rs.next()) {
System.out.print("|");
for(int i=1;i<=fieldNames.size();i++) {
System.out.print(rs.getString(i) + "\t|");
}
System.out.println();
}
}
catch(ClassNotFoundException e) {
System.out.println("com.microsoft.jdbc.sqlserver.SQLServerDriver Is Not Found!!");
e.printStackTrace();
}
catch(SQLException e) {
System.out.println("SQLException: " + e.getMessage());
System.out.println("SQLSata: " + e.getSQLState());
System.out.println("VendorError: " + e.getErrorCode());
e.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
}
catch(SQLException e) {
e.printStackTrace();
}
catch(Exception e ) {
e.printStackTrace();
}
}
}
}
为什么老是有异常 ,连接不成功?我是DB新手,异常如下:
实例化成功 is ok!!
SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
SQLSata: 08001
VendorError: 0
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at cn.wzb.TestJdbcsqlServer.main(TestJdbcsqlServer.java:17)
请指点。
...全文
相关推荐
SQL Server 2000 JDBC驱动
使用JDBC访问SQL Server 2000 数据库所需jar包:msbase.jar、mssqlserver.jar、msutil.jar
VC用ADO的方法连接SQL server 2000
费了不小的功夫才搞通vc连接数据库的一些内容,写出来和大家分享一下!首先SQL server2000 应该设置成混合身份验证模式,再应该添加ado的一个动态链接库,在stdAfx.h文件中添加#import "C:/Program Files/Common Files/System/ADO/msado15.dll" no_namespace /rename("EOF","adoEOF")
sql server2000客户端连接服务器
远程连接SQL SERVER 2000服务器方法 ZDNet软件频道 时间:2008-09-22 作者:ZDNET软件频道 | ZDNET软件频道 我要评论() 本文关键词:企业管理器 TCP/IP 服务器 SQL Server 2000 SQL Server http://soft.zdnet.com.cn/software_zone/2008/0922/1144458.s
配置与SQL_Server2000的ODBC连接
配置与SQL_Server2000的ODBC连接
java与SQL Server2000的连接
NULL 博文链接:https://liuwei8728.iteye.com/blog/504616


Java SE
