java连接SQL数据库执行报错求指导
importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;impor...
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class databaseOpen {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=nicedata", "sa", "123");
if(conn==null){
System.out.println("shibai");
}else{
Statement stc=conn.createStatement();
ResultSet sn=stc.executeQuery("select stuId,stuName,stuSex,stuAge from stuInfo");
while(sn.next()){
String f1=sn.getString("stuId");
String f2=sn.getString("stuName");
String f3=sn.getString("stuSex");
String f4=sn.getString("stuAge");
System.out.println(f1+"\t"+f2+"\t"+f3+"\t"+f4);
}
sn.close();
conn.close();
}
}
}
数据库有nicedata数据库有表,执行提示Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=nicedata", "sa", "123");
有错误; 包也打了的补丁也上了的
执行提示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:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at databaseOpen.main(databaseOpen.java:18) 展开
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class databaseOpen {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=nicedata", "sa", "123");
if(conn==null){
System.out.println("shibai");
}else{
Statement stc=conn.createStatement();
ResultSet sn=stc.executeQuery("select stuId,stuName,stuSex,stuAge from stuInfo");
while(sn.next()){
String f1=sn.getString("stuId");
String f2=sn.getString("stuName");
String f3=sn.getString("stuSex");
String f4=sn.getString("stuAge");
System.out.println(f1+"\t"+f2+"\t"+f3+"\t"+f4);
}
sn.close();
conn.close();
}
}
}
数据库有nicedata数据库有表,执行提示Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=nicedata", "sa", "123");
有错误; 包也打了的补丁也上了的
执行提示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:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at databaseOpen.main(databaseOpen.java:18) 展开
6个回答
展开全部
导入这三个包
msbase.jar
mssqlserver.jar
msutil.jar
driverName的值为:com.microsoft.sqlserver.jdbc.SQLServerDriver;
url的值为jdbc:sqlserver://localhost:1433;DatabaseName=" + database,其中database是你数据库名称
msbase.jar
mssqlserver.jar
msutil.jar
driverName的值为:com.microsoft.sqlserver.jdbc.SQLServerDriver;
url的值为jdbc:sqlserver://localhost:1433;DatabaseName=" + database,其中database是你数据库名称
追问
全部符合了的,包肯定导入了的 数据库补丁也打了数据库服务器也开着的
展开全部
贴异常信息
追问
就是提示Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=nicedata", "sa", "123");
有问题,不知道是不是端口号的问题,在别的电脑上面都能够导出数据出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-02-28
展开全部
lqs
818
818
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-02-27
展开全部
lg
656
656
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-02-28
展开全部
mf
515
515
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询