java - netbeans DataBase retrieve data and display it another jframe textfield -
i want retrieve data , want display jframe . how pass values point .
public void connectdb() { try { //setting driver java derby - select driver class connection properties class.forname("org.apache.derby.jdbc.clientdriver"); //setting database connection through drivermanager.getconnection(dburl, dbusername, dbpwd) con = drivermanager.getconnection( "jdbc:derby://localhost:1527/dbshop", //db url connection properties "apiit", //db username gave when creating db "apiit"); //db password gave when creating db //create java.sql.statement db connection execute sql queries stmt = con.createstatement(); } catch (classnotfoundexception ex) { } catch (sqlexception ex) { system.out.println("error in file"); } }//end connectdb() public void updatepassword(string u) { boolean flag = false; try { //sql update column name tabl name clmn equlng vrbl string sql = "select lastname customerdetails firstname='" + u + "'"; //if update query successful return no. of rows affected resultset rs = stmt.executequery(sql); system.out.println(sql); } catch (sqlexception ex) { system.out.println("error in updatepasswrd"); } // return flag; }
- use
preparedstatement
onstatement
. see using prepared statements more details - return value query need
for example...
public string getlastname(string u) throws sqlexception { string lastname = u; try (preparedstatement ps = con.preparestatement("select lastname customerdetails firstname=?")){ ps.setstring(1, u); try (resultset rs = ps.executequery()) { if (rs.next()) { lastname = rs.getstring(1); } } } return lastname; }
this returns last name customer matching first name. if there more one, first result returned.
you might have @ the try-with-resources statement ideas better resource management
Comments
Post a Comment