建了ACCESS数据库TEST,并添加了数据源SQLTEST,查询的时候出错
import java.sql.*;
import java.lang.*;
public class database {
public static void main(String[] args){
String data="jdbc:odbc:sqltest";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(data,"","");
Statement st=con.createStatement();
ResultSet set=st.executeQuery("select number,name,age "+"from test.testtable "+"where (number='"+args[0]+"')");//错误指向这里,如果把args[0]换成具体的11,22,33,就可以查出来,或者去掉WHERE子句也可以,不知道到底错在那?
while(set.next()){
System.out.println(set.getString("number")+"\t"+set.getString("name")+"\t"+set.getString("age"));
}st.close();
}catch(SQLException s){System.out.print("sql error"+s.toString()+"\t"+s.getErrorCode()+"\t"+s.getSQLState());}
catch(ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}