Errors: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression -
Errors: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression -
the code not allowing me log in database:
bundle business; import java.io.serializable; import java.sql.*; public class pupil implements serializable { private int id; private string password; private string firstname; private string lastname; private string street; private string city; private string state; private double zip; private string email; private double gpa; private string message; /** * no arg constructor sets default value of * client properties empty string value. */ public student() { this.id = 0; this.password = ""; this.firstname = ""; this.lastname = ""; this.street = ""; this.city = ""; this.state = ""; this.zip = 0; this.email = ""; this.gpa = 0; } public void setid(int id) { this.id = id; } public void setpassword(string password) { this.password = password; } public void setfirstname(string firstname) { this.firstname = firstname; } public void setlastname(string lastname) { this.lastname = lastname; } public void setstreet(string street) { this.street = street; } public void setcity(string city) { this.city = city; } public void setstate(string state) { this.state = state; } public void setzip(double zip) { this.zip = zip; } public void setemail (string email) { this.email = email; } public void setgpa(double gpa) { this.gpa = gpa; } public int getid() { homecoming id; } public string getpassword() { homecoming password; } public string getfirstname() { homecoming firstname; } public string getlastname() { homecoming lastname; } public string getstreet() { homecoming street; } public string getcity() { homecoming city; } public string getstate() { homecoming state; } public double getzip() { homecoming zip; } public string getemail() { homecoming email; } public double getgpa() { homecoming gpa; } public string getmessage() { homecoming this.message; } public boolean login(string password) throws sqlexception { boolean yes_no = false; /* verify password against database password userid */ if (password.equals(this.password)) { this.message = "thank you, logged in."; yes_no = true; } else { this.message = "sorry login info seems incorrect."; yes_no = false; } /* returns true or false based on status statement above */ homecoming yes_no; } /** * establishes connection database containing client info * @return connection */ public connection studentconnect() { seek { class.forname("sun.jdbc.odbc.jdbcodbcdriver"); } grab (classnotfoundexception e) { system.out.println("errors: " + e); } connection connect = null; seek { connect = drivermanager.getconnection("jdbc:odbc:regisdb"); } grab (sqlexception e) { system.out.println("you have errors: " + e); } homecoming connect; } /** * takes pupil id , retrieves info customers * info table , stores in properties of client object. * @param id * @throws sqlexception */ public void finddb(int id) { connection con = studentconnect(); statement statement = null; resultset result = null; string sql = "select * students id = " + id + ";"; seek { statement = con.createstatement(); result = statement.executequery(sql); while (result.next()) { this.id = result.getint("id"); this.password = result.getstring("password"); this.firstname = result.getstring("firstname"); this.lastname = result.getstring("lastname"); this.street = result.getstring("street"); this.city = result.getstring("city"); this.state = result.getstring("state"); this.zip = result.getdouble("zip"); this.email = result.getstring("email"); this.gpa = result.getdouble("gpa"); } con.close(); } grab (sqlexception e) { system.out.println("errors: " + e); } } /** * takes in parameters of client database , inserts parameters taken * database add-on of customers database. * @param password * @param firstname * @param lastname * @param street * @param city * @param state * @param zip * @param email * @param gpa * @throws sqlexception */ public void insertdb(string password, string firstname, string lastname, string street, string city, string state, double zip, string email, double gpa) throws sqlexception { connection con = studentconnect(); statement statement; resultset result; int resultval; string sql = "insert students (password, firstname, lastname, street, city, state, zip, email, gpa) values ('" + password + "','" + firstname + "','" + lastname + "','" + street + "','" + city +"','" + state +"','" + zip + "','" + email +"','" + gpa + "');"; seek { statement = con.createstatement(); resultval = statement.executeupdate(sql); system.out.println(resultval); } grab (sqlexception e) { system.out.println("error: " + e); system.out.println(e.getstacktrace()); } { con.close(); } } /** * takes in pupil id , locates client in database, performs * sql update , deletes client database. * @param id * @throws sqlexception */ public void deletedb(int id) throws sqlexception { connection con = studentconnect(); statement statement; int resultval; string sql = "delete students id = " + id + "';"; seek { statement = con.createstatement(); resultval = statement.executeupdate(sql); system.out.println(resultval); } grab (sqlexception e) { system.out.println("errors: " + e); } { con.close(); } } }
i getting error page 1 time seek log on followed errors: java.sql.sqlexception: [microsoft][odbc microsoft access driver] info type mismatch in criteria expression.
error.
here servlet:
@webservlet(urlpatterns = {"/studentloginservlet"}) public class studentloginservlet extends httpservlet { /** * processes requests both http <code>get</code> , <code>post</code> * methods. * * @param request servlet request * @param response servlet response * @throws servletexception if servlet-specific error occurs * @throws ioexception if i/o error occurs */ protected void processrequest(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { response.setcontenttype("text/html;charset=utf-8"); seek (printwriter out = response.getwriter()) { /* todo output page here. may utilize next sample code. */ string id = request.getparameter("id"); string pw = request.getparameter("pw"); system.out.println(id); system.out.println(pw); pupil s1=new student(); s1.finddb(id); string fn=s1.getfirstname(); system.out.println(fn); string ln=s1.getlastname(); system.out.println(ln); string pwdb=s1.getpassword(); system.out.println(pwdb); requestdispatcher rd; httpsession ses1=request.getsession(); ses1.setattribute("s1", s1); if (pw.equals(pwdb)){ rd= request.getrequestdispatcher("/viewstudentschedule.jsp"); rd.forward(request,response); } else{ rd= request.getrequestdispatcher("/loginerror.jsp"); rd.forward(request,response); } } } // <editor-fold defaultstate="collapsed" desc="httpservlet methods. click on + sign on left edit code."> /** * handles http <code>get</code> method. * * @param request servlet request * @param response servlet response * @throws servletexception if servlet-specific error occurs * @throws ioexception if i/o error occurs */ @override protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { processrequest(request, response); } /** * handles http <code>post</code> method. * * @param request servlet request * @param response servlet response * @throws servletexception if servlet-specific error occurs * @throws ioexception if i/o error occurs */ @override protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { processrequest(request, response); } /** * returns short description of servlet. * * @return string containing servlet description */ @override public string getservletinfo() { homecoming "short description"; }// </editor-fold> }
sidenote:
the table called "students" in database , i'm accessing following(correct casing/in order in database):
id password firstname lastname street city state zip email gpa
that error suggests id
column in database numeric; you're trying compare string
value. need alter database id
column kind of varchar
or text
field.
java
Comments
Post a Comment