Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating of data to table in mysql database failed
    text
    copied!<p>The following code doesn't show any error and the code executes but the data that is calculated and stored in rfv is not updated in the database.</p> <pre><code>try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); com.mysql.jdbc.Connection con = (com.mysql.jdbc.Connection) DriverManager.getConnection("jdbc:mysql://localhost:3308/rk","root","root"); ResultSet rsfact=null; PreparedStatement psfact=(PreparedStatement) con.prepareStatement("SELECT * FROM fact"); PreparedStatement psgraph=(PreparedStatement) con.prepareStatement("INSERT INTO graph values(?,?,?,?)"); int cp,ic,rc,fi,ct,tr; while(rsfact.next()) { cp=rsfact.getInt("1"); ic=rsfact.getInt("2"); rc=rsfact.getInt("3"); fi=rsfact.getInt("4"); ct=rsfact.getInt("5"); tr=rsfact.getInt("6"); int rfv; rfv=(cp+ic+rc+fi+ct+tr)/6; graph.setInt(1, rfv); graph.executeUpdate(); } } catch(Exception e){ System.out.println(e); } </code></pre> <p>I checked the code and everything seems to be fine for me but i couldn't figure out the reason for the data which is not inserted into the table. I get the following when this is executed </p> <p>java.lang.NullPointerException</p> <pre><code> try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); com.mysql.jdbc.Connection con = (com.mysql.jdbc.Connection) DriverManager.getConnection("jdbc:mysql://localhost:3308/rk","root","root"); ResultSet rsfact=null; ResultSet rsfault=null; ResultSet rspriority=null; ResultSet rsreq=null; PreparedStatement psfact=(PreparedStatement) con.prepareStatement("SELECT * FROM fact"); PreparedStatement psfault=(PreparedStatement) con.prepareStatement("SELECT * FROM fault"); PreparedStatement pspriority=(PreparedStatement) con.prepareStatement("SELECT * FROM priority"); PreparedStatement psreq=(PreparedStatement) con.prepareStatement("SELECT * FROM req"); PreparedStatement graph=(PreparedStatement) con.prepareStatement("INSERT INTO gr values(?)"); int cp,ic,rc,fi,ct,tr; rsfact = psfact.executeQuery(); rsfault=psfault.executeQuery(); rspriority=pspriority.executeQuery(); rsreq=psreq.executeQuery(); while(rsfact.next()) { cp=rsfact.getInt(1); ic=rsfact.getInt(2); rc=rsfact.getInt(3); fi=rsfact.getInt(4); ct=rsfact.getInt(5); tr=rsfact.getInt(6); int rfv; rfv=(cp+ic+rc+fi+ct+tr)/6; graph.setInt(1, rfv); graph.executeUpdate(); } while(rsfault.next()){ cp=rsfact.getInt(1); fic=rsfact.getInt(2); frc=rsfact.getInt(3); ffi=rsfact.getInt(4); fct=rsfact.getInt(5); ftr=rsfact.getInt(6); int tsfv; tsfv=((fcp*2)+(fic*3)+(frc*4)+(ffi*3.14)+(fct-4)+(ftr+9))/6; graph.setInt(2, tsfv); graph.executeUpdate(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload