database - Having great difficulty implementing login system using SQLite in Java -
private void jbutton1actionperformed(java.awt.event.actionevent evt) { string query; boolean login = false; string username = jtextfield1.gettext(); string password = jtextfield2.gettext(); try{ query = "select (cusername , cpassword) customer cusername = '"+username+"' , cpassword = '"+password+"'"; pst = conn.preparestatement(query); pst.setstring(1, username); pst.setstring(2, password); pst.executequery(); string usercheck = rs.getstring(1); string passcheck = rs.getstring(2); if((usercheck.equals(username)) && (passcheck.equals(password))) { login = true; system.out.println("it works?!"); } else { login = false; system.out.println("psyche, that's wrong number!"); } } catch(exception e){ system.out.println(e); } system.exit(0); }
i'm having difficulty implementing login system in code. i'm trying retrieve text username , password jtextfields , query them database it's not working. @ moment i'm getting
java.lang.arrayindexoutofboundsexception: 0
and unfortunately have no idea why. appreciated.
your query , logic behind got lot of work do:
first of all, if want parametrised query, must use '?' instead of value. pst.setstring work.
secondly, must affect pst.executequery();
resultset
query = "select cusername, cpassword customer cusername = ? , cpassword = ?"; pst = conn.preparestatement(query); pst.setstring(1, username); pst.setstring(2, password); resultset rs = pst.executequery(); if (rs.next()) { string usercheck = rs.getstring(1); string passcheck = rs.getstring(2); }
Comments
Post a Comment