English 中文(简体)
H2:其他电脑的错误
原标题:H2: Error on all other computers

I m using the H2 database in my Java project (embedded mode). On my computer at home everything works, the connection can be established, but on all other computers I always receive the following error:

org.h2.jdbc.JdbcSQLException: Table "CUSTOMERS" not found; SQL statement: SELECT * FROM CUSTOMERS [42102-162]

I m sure, that within the DB everything is alright, it should be something with the connection. But even if I import the h2-1.3.162.jar file, the error still remains.

String dbClass = "org.h2.Driver";
String dbDriver = "jdbc:h2:~/cc";
String user = "user1";
String pass = "test1";
private Connection conn = null;
private Statement stmt = null;
private ResultSet rs = null;

public void connect() {
    boolean done = false;
    //load driver
    try {
        Class.forName(dbClass).newInstance();
        System.out.println("driver loaded"); // This is shown in the Compiler
    } catch (Exception ex) {
        System.out.println("error while loading driver");
        System.err.println(ex);
    }
    // Connection
    try {
        conn = DriverManager.getConnection(dbDriver, user, pass);
        System.out.println("connected"); // This is shown in the Compiler
        done = true;
    } catch (SQLException ex) {
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }
}

public Vector select() {
    data = new Vector();
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT * FROM CUSTOMERS");
        while (rs.next()) {
            Vector row = new Vector();
            row.add(rs.getInt("id"));
            row.add(rs.getString("fname"));
            row.add(rs.getString("lname"));
            row.add(rs.getString("street"));
            row.add(rs.getString("city"));
            row.add(rs.getString("zip"));
            row.add(rs.getString("state"));
            row.add(rs.getString("phone"));
            row.add(rs.getString("birthday"));
            row.add(rs.getString("email"));
            row.add(rs.getInt("code"));
            data.add(row);
        }
        rs.close();
        stmt.close();
    } catch (SQLException ex) {
        System.out.println("error while selecting"); // I receive this error
        System.err.println(ex);
    }
    return data;
}
最佳回答

Finally I figured it out!

It had nothing to do with my tables, the database couldn t be found. When trying to connect to a database which can t be found with String dbDriver = "jdbc:h2:~/cc";, a new database with the name cc (in my case) will be created (of course an empty one with no tables) and the connection is established. That s why I haven t received any connection errors.
In the next step I tried to retrieve some data from the new created empty database and therefore received the error, that my table doesn t exist.

So I changed this line: String dbDriver = "jdbc:h2:file:lib/cc"; and copied into the lib directory of my application my old database cc.h2.db.

所有这一切!

PS:这里是一个简单的问题:

问题回答

这个问题与你的联系有关,因为如果你未能与数据库连接,那么在此之前就有一个例外。 这个问题也是非常清楚的,因此,可以找到<编码>CUSTOMERS的表格。 这可能是因为表格根本不存在,或者连接点在错误的数据库中;试图将表格的全部图谋信息放在桌面上,而不是仅仅放在表格的名称上,并且看看看该表是否可行。

I m sure, that within the DB everything is alright, it should be something with the connection. But even if I import the h2-1.3.162.jar file, the error still remains.

检查你的假设。 这是不正确的。

信中没有任何内容表明你可以连接起来。 您要么与错误的数据库相连接,要么是你与CREATE TABLE CUSTOMERS连接起来的。 (应当称为CUSTOMER,而不是复数)

如果你不再认为你所做的一切是正确的,你就会更快地纠正错误。 你们应该假设一切都是错误的。

我在你赶上这一例外时打印了记分。 这给你提供了更多的信息。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签