【问题标题】:Connecting to H2 wtih PostgreSQL ODBC DriverConnecting to H2 wtih PostgreSQL ODBC Driver
【发布时间】:2022-12-27 04:14:03
【问题描述】:

Successfully started H2 in server mode

C:\Program Files (x86)\H2\bin>java -cp h2-2.0.206.jar org.h2.tools.Server -baseDir ~
TCP server running at tcp://192.168.175.165:9092 (only local connections)
PG server running at pg://192.168.175.165:5435 (only local connections)
Web Console server running at http://192.168.175.165:8082 (only local connections)

However, unable to connect using PostgreSQL latest ODBC Driver 13.02

I get this error message:

SQL Error. Native Code: 110, SQLState: 42001, Return Code: -1
ERROR: Syntax error in SQL statement "set extra_float_digits[*] = 2"; expected "@, AUTOCOMMIT, EXCLUSIVE, IGNORECASE, PASSWORD, SALT, MODE, DATABASE, COLLATION, CLUSTER, DATABASE_EVENT_LISTENER, ALLOW_LITERALS, DEFAULT_TABLE_TYPE, SCHEMA, CATALOG, SCHEMA_SEARCH_PATH, JAVA_OBJECT_SERIALIZER, IGNORE_CATALOGS, SESSION, TRANSACTION, TIME, NON_KEYWORDS, DEFAULT_NULL_ORDERING, LOG, STATEMENT_TIMEOUT, CLIENT_ENCODING, CLIENT_MIN_MESSAGES, JOIN_COLLAPSE_LIMIT, DATESTYLE, SEARCH_PATH"; SQL statement:
SET extra_float_digits = 2 [42001-206]
DETAIL: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "set extra_float_digits[*] = 2"; expected "@, AUTOCOMMIT, EXCLUSIVE, IGNORECASE, PASSWORD, SALT, MODE, DATABASE, COLLATION, CLUSTER, DATABASE_EVENT_LISTENER, ALLOW_LITERALS, DEFAULT_TABLE_TYPE, SCHEMA, CATALOG, SCHEMA_SEARCH_PATH, JAVA_OBJECT_SERIALIZER, IGNORE_CATALOGS, SESSION, TRANSACTION, TIME, NON_KEYWORDS, DEFAULT_NULL_ORDERING, LOG, STATEMENT_TIMEOUT, CLIENT_ENCODING, CLIENT_MIN_MESSAGES, JOIN_COLLAPSE_LIMIT, DATESTYLE, SEARCH_PATH"; SQL statement:
SET extra_float_digits = 2 [42001-206]

Looks like the driver is trying to execute some sql on connecting to the server and when that fails it is failing the connection. Any option to add to the ODBC data source to skip executing the sql that is causing the connection to fail?

【问题讨论】:

    标签: postgresql odbc h2


    【解决方案1】:

    Try setting H2 to the PostgreSQL Compatibility Mode

    jdbc:h2:~/test;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH

    http://h2database.com/html/features.html#compatibility

    Be careful not to change value of DATABASE_TO_LOWER after the creation of database.

    【讨论】:

    • No luck. Connection still fails.
    【解决方案2】:

    Start H2 in Postgres/ODBC Servermode (called PG-Mode). If the database in the connection string is non existent it is automatically created like in embedded mode. If not, you have probably different default settings in your ~/h2.server.properties.

    java h2-2.1.214.jar org.h2.tools.Server -pg
    PG server running at pg://127.0.1.1:5435 (only local connections)
    

    You do NOT need a postgresql-jar as additional driver in your classpath!

    You can set different port number, allow connections from everywhere with specific commandline paras. Use java h2-2.1.214.jar org.h2.Tools.Server -? for all command line options.

    Now test the connection: Connectionstring for the running h2-server in pg-mode above: jdbc:h2:pg://localhost:5435/yourdb

    This connection String works in the SQuirreL SQL Client Tool. Often made mistakes in ODBC/PG Mode:

    1. a missing 'pg://' in the connection string.
    2. no password is used. Connecting via ODBC you MUST use a password.

      If you try to shutdown the H2 Server that runs in PG Mode, it cannot be shutdown with the -tcpShutdown.

      If H2 runs in both modes tcp and pg it shuts down both (not mentioned in the documentation)

      If you start the Server with this line java h2-2.1.214.jar org.h2.Tools.Server

      H2 runs in tcp AND pg mode you probably only want ony of them. Use -tcp or -pg for one of each mode.

      The H2 Documentation for v2.1.2xx says this mode is experimental and should not be used in production environment.

      If you run H2 on your local machine and your application too, use embedded mode. It is much faster and easier to set up.

    【讨论】:

      猜你喜欢
      • 2016-04-19
      • 2019-07-27
      • 2022-12-02
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多