Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Avoid Exception Error on msql.query()

$
0
0

The following Code Snippet gives run-time error

 //===Read From MySQL==========================
  if (msql.connect()) {
    //int recCount = msql.query("SELECT * FROM %s  WHERE %s IS NOT NULL", "interface", "ToSerial");
    //if (recCount > 0) {

    msql.query("SELECT * FROM %s  WHERE %s IS NOT NULL", "interface", "ToSerial");
    try {
      String serialTxt = msql.getString("ToSerial");
      if (serialTxt != null) {
        cp5.get(Textfield.class, "Transmit").setText(serialTxt);
        int deleteID = msql.getInt("ID");
        msql.query( "DELETE FROM %s WHERE  %s = %s", "interface", "ID", deleteID );
      }
    }
    catch (RuntimeException ex) {
      // println(ex);
    }
  }

The Error on the Processing 2.2.1 IDE is as follows:-

SQL.getString(): java.sql.SQLException.
java.sql.SQLException: Illegal operation on empty result set.
    at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:693)
    at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:4832)
    at com.mysql.jdbc.ResultSet.getString(ResultSet.java:4810)
    at com.mysql.jdbc.ResultSet.getString(ResultSet.java:4826)
    at de.bezier.data.sql.SQL.getString(Unknown Source)
    at CIOMSerial.draw(CIOMSerial.java:107)
    at processing.core.PApplet.handleDraw(PApplet.java:2386)
    at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
    at processing.core.PApplet.run(PApplet.java:2256)
    at java.lang.Thread.run(Unknown Source)

After sometime, it fails to connect to the database. I couldn't find a way to check if the Query() has returned any records or not. Please anyone, kindly provide a way out.


Viewing all articles
Browse latest Browse all 2896

Trending Articles