Is it possible to call H2 from bash

8,389 views
Skip to first unread message

Cecil Westerhof

unread,
Apr 14, 2013, 6:20:33 AM4/14/13
to h2-da...@googlegroups.com
I have the web and tcp server running. From java (scala really) I make a connection with jdbc:h2:tcp://localhost/. Is it also possible to retrieve a query from a bash script? Like it can be done with mySQL. I could of-course call a java program, but this would have a lot of overhead. So I was wondering if there was a more efficient way.

--
Cecil Westerhof

Noel Grandin

unread,
Apr 14, 2013, 12:17:48 PM4/14/13
to h2-da...@googlegroups.com
The Shell or the RunScript tool should do the job.

http://h2database.com/html/tutorial.html#command_line_tools

Cecil Westerhof

unread,
Apr 14, 2013, 3:06:58 PM4/14/13
to h2-da...@googlegroups.com
2013/4/14 Noel Grandin <noelg...@gmail.com>

The Shell or the RunScript tool should do the job.

http://h2database.com/html/tutorial.html#command_line_tools

I'll look into it. But in this way I start a jvm. That is quite expensive I think. There is not a better way?

--
Cecil Westerhof

Cecil Westerhof

unread,
Apr 14, 2013, 3:16:41 PM4/14/13
to h2-da...@googlegroups.com
2013/4/14 Cecil Westerhof <cldwes...@gmail.com>

I just tested it with a simple query:
    SELECT quote FROM quotes LIMIT 10

The query itself took 49 ms. The total took .7 seconds. So the overhead is a factor 14. That is a lot. But for the moment it is good enough for me. I will not do that many queries I think.

If I need to do more, I properly should recode the bash script to a scala script. Looking at the above figure, that does not need to be very expensive.

--
Cecil Westerhof

Noel Grandin

unread,
Apr 15, 2013, 2:56:15 AM4/15/13
to h2-da...@googlegroups.com, Cecil Westerhof

On 2013-04-14 21:06, Cecil Westerhof wrote:
>
> I'll look into it. But in this way I start a jvm. That is quite
> expensive I think. There is not a better way?
>

How exactly do you think H2 works?

Ryan How

unread,
Apr 15, 2013, 3:56:40 AM4/15/13
to h2-da...@googlegroups.com
It would be like this for any java program you call from a bash script. I'm not sure if you can maybe start a postgres server in H2 and use a postrgres command line tool?

Only other alternative would be to write a little java daemon you could leave running which you could send commands to from a bash script and get a response from. Probably using pipes could be quite simple, the java program just reads commands from the pipe (SQL) and outputs the resultset. Then your bash script can just write to the pipe and read a response from it. I'm sure there are much better ways, I haven't done a lot with bash scripts.
Cecil Westerhof --
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ryan How

unread,
Apr 15, 2013, 4:00:39 AM4/15/13
to h2-da...@googlegroups.com
Or you could try something like this

https://github.com/flatland/drip

Thomas Mueller

unread,
Apr 15, 2013, 3:13:02 PM4/15/13
to H2 Google Group
Hi,

We might want to add a HTTP(S) interface, so you could use "curl" or "wget" to query the database. But this is not planned.

Regards,
Thomas


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages