下面的代码显示了java.sql.SQLException。任何人都可以帮我修复这个
Class.forName("oracle.jdbc.driver.OracleDriver");
String lname=request.getParameter("lastname");
String uname=request.getParameter("username");
String fname=request.getParameter("firstname");
String cemail=request.getParameter("email");
String pswd=request.getParameter("password");
String cpswd=request.getParameter("conformpassword");
String sex=request.getParameter("gender");
long phon=Long.parseLong(request.getParameter("mobile"));
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "admin");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("insert into users values('" + uname + "','" + fname + "','" + lname + "','" + cpswd + "',"+ phon + ",'" + cemail + "','" + sex + "');");
答案 0 :(得分:0)
而不是:
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("insert into users values('" + uname + "','" + fname + "','" + lname + "','" + cpswd + "',"+ phon + ",'" + cemail + "','" + sex + "')");
我建议做以下事情:
PreparedStatement st = con.prepareeStatement("insert into users values(?,?,?,?,?,?,?);");
st.setString(1, uname);
st.setString(2, fname);
st.setString(3, lname);
st.setString(4, cpswd);
st.setLong(5, phon);
st.setString(6, cemail);
st.setString(7, sex);
ResultSet rs = st.executeQuery();
您的问题并不明显,但我使用PreparedStatement可以防止您将遇到的未来问题。我希望有所帮助。