sql - JAVA update Database - wrong -


package application;  import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement;  public abstract class query {      private static final string driver_classname = "org.sqlite.jdbc";     private static final string password = "";     private static final string username = "";      protected static string base = "data/pezaldb";     private static string jdbc_url = "jdbc:sqlite:" + base + ".db";      protected static connection connection;     protected static statement statement;     public static resultset resultset;      public static void connecttodatabase() throws classnotfoundexception, sqlexception {         class.forname(driver_classname);         connection = drivermanager.getconnection(jdbc_url, username, password);     }      public static void executesql(string sql) throws sqlexception {          statement = connection.createstatement();         resultset = statement.executequery(sql);     }      public static void close() throws sqlexception {         resultset.close();         statement.close();         connection.close();     }  }  public class tabledb {      private int id;     private string namepl;     private string nameen;      public tabledb(string namepl, string nameen) {         this.namepl = namepl;         this.nameen = nameen;     } }  public class querymethods extends query {      static string table = "dictionary";     static string sql;      public static void addvalue() {         try {             connecttodatabase();              sql = "update dictionary set namepl = 'qwe' id = 2";              executesql(sql);             close();         } catch (classnotfoundexception e) {             e.printstacktrace();         } catch (sqlexception e) {             e.printstacktrace();         }     }      public static void main(string[] args) {          addvalue();      } } 

i have problem :

java.sql.sqlexception: query not return resultset     @ org.sqlite.jdbc3.jdbc3statement.executequery(jdbc3statement.java:85)     @ application.querymethods.addvalue(querymethods.java:18)     @ application.testquery.main(testquery.java:10) 

what wrong? when read database ok more function wrong.

did not work update , insert .................................................................................................................................................................................................................................................

you trying execute sql update statement executequery() method. executequery() cannot take statements update database, such update, insert or delete. replace line with:

int rowsupdated = statement.executeupdate(sql); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -