JAV连接SQL server2000时出错Error establishing socket.
这是我的程序:packageinsertsql;importjava.sql.*;importjava.net.URL;publicclassInsertSql{publ...
这是我的程序:
package insertsql;
import java.sql.*;
import java.net.URL;
public class InsertSql {
public static void main(String args[]){
String url="jdbc:microsoft:sqlserver://locallhost:1433;" +
"User=public;Password=javadb;DatabaseName=Northwind";
//设置三个SQL语句
String query="Select * Frome FirstTable";
String query1="Insert Into FirstTable(ID,Name,Types,Description,Others)" +
"Values(6,'java','IT Technology','this book is for programmer','great')";
String query2="Insert Into FirstTable(ID,Name,Types,Description,Others)" +
"Values(7,'Amercian Culture','literature'," +
"'this book is for people who wants to know something about US Culture','good')";
try{
//加载Sql Server JDBC驱动程序
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(url);
//建立一个Statement对象,用这个对象向驱动程序发送SQL语句
Statement stmt=con.createStatement();
//提交两个不同的插入操作
stmt.executeUpdate(query1);
stmt.executeUpdate(query2);
ResultSet rs=stmt.executeQuery(query);
//显示结果集的所有行和列
dispResultSet(rs);
rs.close();
stmt.close();
con.close();
}catch(SQLException ex){
System.out.println("\n***SQLException caught***\n");
while(ex!=null){
System.out.println("SQLState:"+ ex.getSQLState());
System.out.println("Message: "+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println();
}
}catch(java.lang.Exception ex){
//捕获例外并显示它的详细信息
ex.printStackTrace();
System.out.println("\n***这是里有误***\n");
}
}
private static void dispResultSet(ResultSet rs)throws SQLException{
int i;
//取得结果集的无数据
ResultSetMetaData rsmd=rs.getMetaData();
//获得结果集的列数
int numCols=rsmd.getColumnCount();
//显示列的标题
for(i=1;i<=numCols;i++){
if(i>1)
System.out.print(", ");
System.out.print(rsmd.getColumnLabel(i));
}
System.out.println("");
System.out.println("");
//显示结果集中的所有数据
boolean more=rs.next();
while(more){
//循环显示结果表明集中的所有数据
for(i=1;i<=numCols;i++){
if(i>1)
System.out.println(", ");
System.out.println(rs.getString(i));
}
System.out.println("");
//获得下一行数据
more=rs.next();
}
}
}
各位朋友给看看吧,实在是找不出错误,我找过SP4的补丁,但还是出现这个问题,先谢谢了!!! 展开
package insertsql;
import java.sql.*;
import java.net.URL;
public class InsertSql {
public static void main(String args[]){
String url="jdbc:microsoft:sqlserver://locallhost:1433;" +
"User=public;Password=javadb;DatabaseName=Northwind";
//设置三个SQL语句
String query="Select * Frome FirstTable";
String query1="Insert Into FirstTable(ID,Name,Types,Description,Others)" +
"Values(6,'java','IT Technology','this book is for programmer','great')";
String query2="Insert Into FirstTable(ID,Name,Types,Description,Others)" +
"Values(7,'Amercian Culture','literature'," +
"'this book is for people who wants to know something about US Culture','good')";
try{
//加载Sql Server JDBC驱动程序
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection(url);
//建立一个Statement对象,用这个对象向驱动程序发送SQL语句
Statement stmt=con.createStatement();
//提交两个不同的插入操作
stmt.executeUpdate(query1);
stmt.executeUpdate(query2);
ResultSet rs=stmt.executeQuery(query);
//显示结果集的所有行和列
dispResultSet(rs);
rs.close();
stmt.close();
con.close();
}catch(SQLException ex){
System.out.println("\n***SQLException caught***\n");
while(ex!=null){
System.out.println("SQLState:"+ ex.getSQLState());
System.out.println("Message: "+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println();
}
}catch(java.lang.Exception ex){
//捕获例外并显示它的详细信息
ex.printStackTrace();
System.out.println("\n***这是里有误***\n");
}
}
private static void dispResultSet(ResultSet rs)throws SQLException{
int i;
//取得结果集的无数据
ResultSetMetaData rsmd=rs.getMetaData();
//获得结果集的列数
int numCols=rsmd.getColumnCount();
//显示列的标题
for(i=1;i<=numCols;i++){
if(i>1)
System.out.print(", ");
System.out.print(rsmd.getColumnLabel(i));
}
System.out.println("");
System.out.println("");
//显示结果集中的所有数据
boolean more=rs.next();
while(more){
//循环显示结果表明集中的所有数据
for(i=1;i<=numCols;i++){
if(i>1)
System.out.println(", ");
System.out.println(rs.getString(i));
}
System.out.println("");
//获得下一行数据
more=rs.next();
}
}
}
各位朋友给看看吧,实在是找不出错误,我找过SP4的补丁,但还是出现这个问题,先谢谢了!!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询