is there a tutorial anywhere on how to use prepared statements with H2 ?

944 views
Skip to first unread message

Christian MICHON

unread,
Mar 30, 2012, 2:13:29 PM3/30/12
to h2-da...@googlegroups.com
Hi,

I've now been using H2 for almost a year, extremely happy about its ease of use and performances.

I'm currently trying to import lot of data into several tables, using always similar insert commands.

I read somewhere that prepared statements could help speeding up partially (I've already experienced the usal no log, no undo and cache hints). I've been looking in many places, and I could only find a few java source files, but no tutorial, no concrete example.

Where could I find some?

Thanks again for this very nice tool.

Regards,
Christian

Noel Grandin

unread,
Mar 30, 2012, 4:28:05 PM3/30/12
to h2-da...@googlegroups.com
google for "jdbc preparedstatement"

> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/h2-database/-/Pv6T6eatQCoJ.
> To post to this group, send email to h2-da...@googlegroups.com.
> To unsubscribe from this group, send email to
> h2-database...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.

Carlos Hoces

unread,
Mar 30, 2012, 4:39:32 PM3/30/12
to h2-da...@googlegroups.com

Christian MICHON

unread,
Mar 30, 2012, 5:07:53 PM3/30/12
to h2-da...@googlegroups.com
Thanks guys. As I'm actually using jruby (and not really java), this will be interesting to code...

I still find it strange no one ever posted any tutorial on H2 db + jdbc preparedstatement...

I will experiment and come back to this group if I meet issues.

--
Christian

> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Christian MICHON

unread,
Mar 30, 2012, 5:50:04 PM3/30/12
to h2-da...@googlegroups.com
Hi again,

It was easy after all to make it work with jruby. For those who might be interested one day... here is the code...

require 'java'
java_import org.h2.Driver
java_import java.sql.DriverManager
java_import java.sql.PreparedStatement
conn = Java::JavaSql::DriverManager.getConnection('jdbc:h2:testdb','','')
stmt = conn.createStatement()
stmt.executeUpdate "DROP TABLE IF EXISTS TEST"
stmt.executeUpdate "CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
stmt.executeUpdate "INSERT INTO TEST VALUES(1, 'Hello')"
stmt.executeUpdate "INSERT INTO TEST VALUES(2, 'Goodbye')"
stmt.executeUpdate "INSERT INTO TEST VALUES(3, 'World')"
prep = conn.prepareStatement "DELETE TEST WHERE ID = ?"
prep.setInt(1,2)
prep.executeUpdate()
conn.close()

Thanks again for the google hints and this great db!

--
Christian
Reply all
Reply to author
Forward
0 new messages