get value from database using java -


this code doesnt work , please helpp , want read value database , have 1 condition .

private void jcombobox1actionperformed(java.awt.event.actionevent evt) { string url = "jdbc:mysql://localhost:3306/joebdd";  string driver = "com.mysql.jdbc.driver";  string user = "root";  string pass = "12345";       string value=(jcombobox1.getselecteditem().tostring());       try  {      class.forname(driver).newinstance();   connection con = (connection)drivermanager.getconnection(url,user,pass);   string sql1 = "select price produit productname='"+value+"'";  preparedstatement pst = con.preparestatement(sql1);  resultset rs = (resultset) pst.executequery(sql1);    jtextfield3.settext(rs.getstring(1));       }   catch(  classnotfoundexception | instantiationexception | illegalaccessexception |   sqlexception e){  joptionpane.showmessagedialog(null, e);  }} 

check resultset has value or not, rs.next().

    string pass = "12345";          string value=(jcombobox1.getselecteditem().tostring());     try     {         class.forname(driver).newinstance();         connection con = (connection)drivermanager.getconnection(url,user,pass);         string sql1 = "select price produit productname='"+value+"'";          preparedstatement pst = con.preparestatement(sql1);         resultset rs = (resultset) pst.executequery(sql1);         if(rs.next())         {             jtextfield3.settext(rs.getstring(1));         }         else         {             jtextfield3.settext("");         }      }     catch(  classnotfoundexception | instantiationexception | illegalaccessexception | sqlexception e)     {         joptionpane.showmessagedialog(null, e);     } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -