用的最简单的jdbc连接数据库,拼sql语句插入数据库,得到前台传过来的用户的信息username 和userpass 然后存入数据库,这应该怎么写?public boolean addUser(User user) {
boolean flag = false;
try{
String sql = "insert into t_user values (null, '?', '?','normaluser')";
//System.out.println("here!!!!!!!!!!");//debug
this.pstmt = this.conn.prepareStatement(sql);
System.out.println(user.getUsername());//debug
this.pstmt.setString(1, user.getUsername());
this.pstmt.setString(2, user.getPassword());
this.pstmt.executeUpdate();
flag = true;
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(this.pstmt!=null){
this.pstmt.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
return flag;
}我的插入数据库那一段代码是这样写的,dbconnection  我写成了  一个dbconnection的包  上面已经打开了连接  现在就是往数据库里写数据有问题  不知道sql是不是这样拼的?我的表里有四个字段  id auto_increment ,username, userpass, privilege(权限)   用的是mysql数据库。