当前位置: 技术问答>java相关
请教关于SQLServer连接的问题
来源: 互联网 发布时间:2015-04-28
本文导语: classpath已设置完毕,但还是出现以下问题,请各位老大帮帮忙,多谢 java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]ResultSet can not re-read row data for column 1. import java.sql.*; class Conn{ public Connection conn = null; pub...
classpath已设置完毕,但还是出现以下问题,请各位老大帮帮忙,多谢
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]ResultSet can not re-read row data for column 1.
import java.sql.*;
class Conn{
public Connection conn = null;
public Conn(){
String sDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("opendb():"+e.getMessage());
}
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://server:1433","OA","meijin");
conn.setCatalog("OA");
}
catch (SQLException ex){
System.err.println("rs.executeQuery:"+ex.getMessage());
}
}
public static void main( String argv[] )
{
Conn Conn = new Conn();
try{
Conn conn = new Conn();
Statement stmt = conn.conn.createStatement();
String sql="select * from OA_Employee where Employee_ID=4";
ResultSet rs=stmt.executeQuery(sql);
if(!rs.next()){
stmt.close();
}
String strEmpName = rs.getString("Employee_Name");
String strEmpID = rs.getString("Employee_ID");
System.out.println( "succeed" );
rs.close();
}catch(SQLException ex){
System.out.println(ex+"" );
}
System.out.println( "succeed@!!@!" );
}
}
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]ResultSet can not re-read row data for column 1.
import java.sql.*;
class Conn{
public Connection conn = null;
public Conn(){
String sDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("opendb():"+e.getMessage());
}
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://server:1433","OA","meijin");
conn.setCatalog("OA");
}
catch (SQLException ex){
System.err.println("rs.executeQuery:"+ex.getMessage());
}
}
public static void main( String argv[] )
{
Conn Conn = new Conn();
try{
Conn conn = new Conn();
Statement stmt = conn.conn.createStatement();
String sql="select * from OA_Employee where Employee_ID=4";
ResultSet rs=stmt.executeQuery(sql);
if(!rs.next()){
stmt.close();
}
String strEmpName = rs.getString("Employee_Name");
String strEmpID = rs.getString("Employee_ID");
System.out.println( "succeed" );
rs.close();
}catch(SQLException ex){
System.out.println(ex+"" );
}
System.out.println( "succeed@!!@!" );
}
}
|
if(rs.next()){
String strEmpName = rs.getString ("Employee_Name");
String strEmpID = rs.getString ("Employee_ID");
System.out.println( "succeed" );
}
rs.close();
stmt.close();
String strEmpName = rs.getString ("Employee_Name");
String strEmpID = rs.getString ("Employee_ID");
System.out.println( "succeed" );
}
rs.close();
stmt.close();