简体   繁体   中英

Java & HSQLDB INSERT TO problem

I've a problem when I try to insert data into a hsqldb with a Java class : The code is :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;




     public class Main {
         public static void main(String[] args) throws ParseException {
             try {
                 Connection con = null;
                 String url = "jdbc:hsqldb:file:../db/db";
                 Class.forName("org.hsqldb.jdbcDriver");
                 con = DriverManager.getConnection(url, "sa", null);
                 Statement statement = con.createStatement();
                 Statement stm1 = con.createStatement();

                 statement.executeUpdate("INSERT INTO \"vacDeGroupe\"(\"type\") VALUES ('test')");
                 ResultSet rs = stm1.executeQuery("SELECT * FROM \"vacDeGroupe\"");
                 while(rs.next()) {
                     System.out.println(rs.getString("type"));
                 }

                 stm1.close();
                 statement.close();
                 con.close();

             }
             catch(ClassNotFoundException e) {

             } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
         }

        }

If I exec this code I have my entries + the new I have INSERT INTO my database. But, after if I only do the executeQuery(), the row I have insert is not in my database. I've checked, autoCommit is on true.

... I don't understand what's happened.

(I'm french so I'm sorry if there is some english errors)

executeUpdate for INSERT, not executeQuery . And it does not return a ResultSet ; it's number of affected rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM