java - Server using a table that I didn't even mention in my code -
im using netbeans 8.0 . i've created table "full" in database "face" . earlier , created table "student" in database "rishi" . , after deleting table database "rishi" & after changing database "full" , following error :-
java.sql.sqlexception: base table or view not found message server: "table 'face.student' doesn't exist".
here's html code :-
<html> <head> <title>todo supply title</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <center> <h1>login !</h1> <hr> <form action = "check" method = "post"> <pre> enter email : <input type = "text" name = "email"> enter password : <input type = "password" name = "pass"> <input type = "submit" value = "login"> </pre> </form> <hr> <h3>new ? sign in today !</h3> <form action = "new" method = "post"> <pre> enter name : <input type = "text" name = "user"> enter email : <input type = "text" name = "newemail"> enter password : <input type="password" name = "newpass"> re-enter password : <input type="password" name = "repass"> <input type = "submit" value = "sign up"> </pre> </form> </center> </body> </html>
and here's servlet :-
public class new extends httpservlet { @override protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { printwriter out = response.getwriter(); string name = request.getparameter("user"); string email = request.getparameter("newemail"); string pass = request.getparameter("newpass"); string repass = request.getparameter("repass"); try { class.forname("com.mysql.jdbc.driver"); connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/face" , "root" , "root"); statement st = con.createstatement(); resultset r = st.executequery("select * full"); int flag = 0; while(r.next()) { string s = r.getstring(2); if(pass.equals(repass) || email.equals(s)) { flag = 1; } else { flag = 2; } if(flag == 2) { response.sendredirect("fail2.html"); } else { string qr = string.format("insert student values('%s','%s','%s')" , name , email , pass); st.executeupdate(qr); response.sendredirect("home.html"); } } catch (classnotfoundexception ex) { out.println("cannot load driver !"); } catch (sqlexception ex) { out.println(ex); } } @override protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { doget(request,response); } }
what possibly going wrong ?
thank in advance !
sorry bad - re-read question.. in fact database connection fine, because still have database face
the problem insert statement - trying insert data table non existent in database.
string qr = string.format("insert student values('%s','%s','%s')" , name , email , pass);
this problem lies - either have make table student
in "new" database, or change existing in db.
string qr = string.format("insert " insert valid table name here "values('%s','%s','%s')" , name , email , pass);
but want address different issue - not understand why have ?
if(pass.equals(repass) || email.equals(s)) { flag = 1; } else { flag = 2; } if(flag == 2) { response.sendredirect("fail2.html"); } else { string qr = string.format("insert student values('%s','%s','%s')" , name , email , pass); st.executeupdate(qr); response.sendredirect("home.html"); }
this block seems (to me) redundat because check if credentials mach if set flag 1 - far good, if don't set flag 2. thats fine - why have if statement check if flag 2 ? , if redirect fail.html. otherwise query... kind of redundand ( unless expect more 2 flags) if dont block below lot nicer solution
if(pass.equals(repass) || email.equals(s)) { string qr = string.format("insert student values('%s','%s','%s')" , name , email , pass); st.executeupdate(qr); response.sendredirect("home.html"); } else { response.sendredirect("fail2.html"); }
Comments
Post a Comment