[求助]看看这个JDBC操作错误?
import java.sql.*;public class Demo{
protected final String driver="sun.jdbc.odbc.JdbcOdbcDriver";
protected final String source="jdbc:odbc:StudentInfo";
protected Connection connection;
protected Statement statement;
public void mm()throws SQLException{
try{
Class.forName(driver);
connection=DriverManager.getConnection(source);
statement=connection.createStatement();
String sql="CREATE TABLE 0511802006(Hid text,Hname text,Hstatus bit) ";
String s1="INSERT INTO 0511802006(Hid,Hname,Hstatus) VALUES ( '2','2002','1')";
statement.executeUpdate(s1);
ResultSet rs=statement.executeQuery(sql);
while(rs.next()){
String id=rs.getString("Hid");
String name=rs.getString("Hname");
String status=rs.getString("Hstatus");
System.out.println("Hid:"+"\t"+"Hname:"+"\t"+"Hstatus");
System.out.println(id+"\t"+name+"\t"+status);
}
statement.close();
}catch(SQLException e){
e.printStackTrace();
}catch(Exception exc){
exc.printStackTrace();
}
}
public static void main(String[] args)throws SQLException{
Demo d=new Demo();
d.mm();
}
}
这个程序执行后,在Acess2000中插入两个数据,这是为什么?
搜索更多相关的解决方案:
JDBC
----------------解决方案--------------------------------------------------------
回复:(jdk2006)[求助]看看这个JDBC操作错误?
String sql="CREATE TABLE 0511802006(Hid text,Hname text,Hstatus bit) ";String s1="INSERT INTO 0511802006(Hid,Hname,Hstatus) VALUES ( '2','2002','1')";
statement.executeUpdate(s1);
ResultSet rs=statement.executeQuery(sql);//这个也行吗?sql不是一个查询语句啊
while(rs.next()){
----------------解决方案--------------------------------------------------------
同楼上,你的查询语句没有写对
----------------解决方案--------------------------------------------------------
对这个SQL语句复制错了
String s="CREATE TABLE 0511802006(Hid text,Hname text,Hstatus bit) ";
statement.executeUpdate(s);
[此贴子已经被作者于2007-10-5 10:02:03编辑过]
----------------解决方案--------------------------------------------------------
粗心
----------------解决方案--------------------------------------------------------