The Artima Developer Community
Sponsored Link

Java Buzz Forum
SQL Scripts in Java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
SQL Scripts in Java Posted: Nov 17, 2005 11:41 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: SQL Scripts in Java
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

Devender demonstrated shelling out to SQL*Plus to run a script, figured I had to trackback with a jDBI example that doesn't have to shell out, just for alternatives (and because this is a common mechanism for me to construct test schema =)

Our script, with various comment styles (this was taken from the regression tests for jDBI, btw):

-- insert 3 lines
insert into something(id, name) values (1, 'one');
# line 2
insert into something (id, name) values (2, 'two');
// line 3
insert into something (id, name) values (3, 'three');

and our code to run the script:

    public void testScriptExample() throws Exception
    {
        Handle h = DBI.open("jdbc:derby:testing");
        assertEquals(0, h.query("select * from something").size());
        h.script("src/test-etc/insert-script-with-comments.sql");
        assertEquals(3, h.query("select * from something").size());
        h.close();
    }

Shelling out to SQL*Plus is always an option I guess =) This did remind me that I need to change jDBI to use a script locator mechanism analogous to its named statement locator, in case you want to store your scripts on a web server, in the database, in JNDI, or... wherever comes to mind. Guess 1.3.3 may be out soon!

Read: SQL Scripts in Java

Topic: Be Cheerful Or Be Home Mandates IT Firm Previous Topic   Next Topic Topic: File Transfer

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use