是这样的。我在百度云平台建了个数据库。然后服务器那块是用struct2写的。在登录模块那里有查询数据库操作.然后很成功.在注册模块就出了错.一路追查下去结果发现是插入sql语句未执行.然后继续尝试,update也不执行。于是默默发现除了查询,只要要写进去的sql语句都不执行。而且这玩意还不好google。求各位大神帮帮忙啊。在此谢过了
附上代码
public class RegisterSQL { public List registerList; public String register(){ String b=new String("") ; int i = 0; User user=registerList.get(0); ResultSet rs = null; MySql db=new MySql(); Connection conn=db.connectMySQL(); try { PreparedStatement ps=conn.prepareStatement("select * from user where username=?"); ps.setString(1,user.getUsername()); rs=ps.executeQuery(); if (rs.next()) { PreparedStatement ps1=conn.prepareStatement("insert into user(username,password,age,sex,phone) values (?,?,?,?,?)"); ps1.setString(1,user.getUsername()); ps1.setString(2,user.getPassword()); ps1.setString(3,user.getAge()); ps1.setString(4,user.getSex()); ps1.setString(5,user.getPhone()); i=ps1.executeUpdate(); if (i>0) { b="your register success"; } else { b="something wrong with the SQL,so please try again"; } } else { System.out.println("test1"); String sql = "insert into user(username,password,age,sex,phone)"+" values('"+user.getUsername()+"','"+user.getPassword()+"','"+user.getAge()+"','"+user.getSex()+"','"+user.getPhone()+"')"; System.out.println("test2"); db.excute(sql); b="ok"; } } catch (SQLException e) { e.printStackTrace(); } return b; }
闭关修行中......