MengL_unfor
2017-05-27 08:57
采纳率: 100%
浏览 2.3k
已采纳

求助大神 JDBC数据插入不进数据库

public static void Mysql_save(String name, String num, String sex, int age){
String name_save = name;
String num_save = num;
String sex_save = sex;
int age_save = age;
String password_save = num;
try {
Connection conn = DriverManager.getConnection(url, username, password);
if(!conn.isClosed()){

System.out.println("Succeeded connecting to the Database!");

String sql = "insert into user(name,num,age,sex,password) values (?,?,?,?,?)";

String sql1 = "insert into base(ANAME,NUM,ACCOUNT) values (?,?,?)";
PreparedStatement st= (PreparedStatement) conn.prepareStatement(sql);
st.setString(1, name_save);
st.setString(2, num_save);
st.setInt(3, age_save);
st.setString(4, sex_save);
st.setString(5, password_save);
st.executeUpdate(sql);
PreparedStatement st1= (PreparedStatement) conn.prepareStatement(sql1);
st1.setString(1, name_save);
st1.setString(2, num_save);
st1.setInt(3, 0);
st1.executeUpdate(sql1);

System.out.println("注册成功");

} conn.close();
}catch(Exception e){
// System.out.println(e);
}
}
数据就是写不进数据库里面

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

11条回答 默认 最新

相关推荐 更多相似问题