日期:2014-05-17  浏览次数:20835 次

新手,请教一下,我的这个程序为什么输入以后回车是IOException
public class userStatusServiceImpl {
 
public static void main(String args[]){
String temp=null;
String sqlDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
  String url="jdbc:odbc:myIM"; 
Connection con = null;
Statement stmt=null;
ResultSet rs = null;
BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); 
try { 
try { 
Class.forName(sqlDBDriver); //加载驱动 
}catch(ClassNotFoundException e){ 
System.out.println("Can not load Jdbc-Odbc Bridge Driver"); 
System.err.print("ClassNotFoundException:"); 
System.err.println(e.getMessage()); 

con=DriverManager.getConnection(url,"sa","1qazxsw23edc"); //使用SQL-SERVER2000认证 
stmt=con.createStatement(); 
temp=input.readLine(); 
String sql="select status from icq where icqno=+temp";
rs=stmt.executeQuery(sql);
int status=rs.getInt("status");
if(status==0){
System.out.println("用户不在线");}
else {
if(status==1){
System.out.println("用户在线");}
else{
System.out.println("用户不存在");
}
}
rs.close();
stmt.close();
con.close();
}catch(Exception e) { 
System.out.println("IOException");

}

------解决方案--------------------
System.out.println("IOException");
换成
e.printStackTrace();

看看输出是什么?
------解决方案--------------------
String sql="select status from icq where icqno=+temp 你这语句都不正确
------解决方案--------------------
Java code

rs=stmt.executeQuery(sql);
int status=rs.getInt("status");
if(status==0){
System.out.println("用户不在线");}
else {
if(status==1){
System.out.println("用户在线");}
else{
System.out.println("用户不存在");
}
}