Has anyone tried to create stored procedures using the H2 database?
相关问题
- What is the best way to cache a table from a (SQL)
- NOT DISTINCT query in mySQL
- Flush single app django 1.9
- keeping one connection to DB or opening closing pe
- H2 database: clustered indexes support
相关文章
- 小型数据库(SQLite,Derby,H2)可以存储多少数据?
- Connection pooling vs persist connection mysqli
- SQL Server 2008: Joining results of STORED PROCEDU
- Is SaveChanges() Necessary with Function Imports (
- Can I lazy load a navigation property by delegatin
- Speed up sqlFetch()
- How Do I Seed My Database in the setupBeforeClass
- I set a MySQL column to “NOT NULL” but still I can
To access the database within a Java function, you do need a connection. For H2, there are two ways to get such a connection:
Solution 1: If the first parameter of the Java function is a
java.sql.Connection
, then the database provides the connection. For SQL, this is a 'hidden' parameter, meaning you can't and don't need to set it explicitly. This is documented: User-Defined Functions and Stored Procedures, "Functions That Require a Connection". Example:Solution 2: For compatibility with Apache Derby and Oracle, You can open a new connection within the Java function using
DriverManager.getConnection("jdbc:default:connection")
. This feature is available in H2 version 1.3.151 and newer, and it it disabled by default. To enable it, append;DEFAULT_CONNECTION=TRUE
to the database URL. It's a problematic feature because the Oracle JDBC driver will try to resolve this database URL if it is loaded before the H2 driver. So basically you can't use the feature if the Oracle driver is loaded (I consider this a bug in the Oracle driver).