开发者

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();

     开发者_JS百科        }
             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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜