//底层UserHandle
...
public UserHandle(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin127.0.0.1:1521:Beyond";
String user = "beyond";
String psd = "beyond";
tableName = "USER";
cn = DriverManager.getConnection(url,user,psd);
stmt = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); //是不是这里要指明stmt的类别允许更新才行,我是这么做的,可以更新,另外通过stmt.executeQuery(sql)应该可以更新!!
}
catch(Exception ex){
System.out.println(ex.toString());
}
}
public void addUser(String sql)throws Exception{
try{
stmt.executeQuery(sql);
}
catch(SQLException ex){
System.out.println("SQL statement is wrong!");
System.out.println(ex.toString());
throw ex;
}
}
}
//上层类DoSQL
...
public void addUser(){
UserHandle uh = new UserHandle();
String sql = "Insert Into USER Values('";
if(!checkIntegrality()){
return;
}
sql += (userID +"','"+ userName +"','"+ realName +"','"+ sex +"','"
+ address +"','"+ telephone +"','"+ mobile +"','"+ email+"')");
try{
uh.addUser(sql); //调用UserHandle.addUser();
}
catch(Exception ex){
errorInfo.addElement(ex.toString());
}
}
//我连的Oracle数据库,希望能给你点帮助,Good luck!