You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Magnus Prime <ma...@hotmail.com> on 2008/03/11 18:47:48 UTC
Reading DDL SQL from JAR
Hi All,
I know there is probably a really easy way/answer to this, but I am struggling a bit.
I am trying to create a simple GUI app with Derby as my Embedded DB.
I have my SQL script in a .sql file, which is inside my JAR. It contains all the create table statements I need to create a new database in my app. (Application allows multiple databases, so thats why I am trying to do this.) I am not having trouble reading the sql file, as the getResourceAsStream method works fine.
After I have read in my sql file into a String type, I try to do an execute on the dbconnection:
Statement stmt = dbconn.createStatement();
stmt.execute(sql);
I have also tried executeUpdate and executeQuery.
Each time it complains either that it encountered a ; at the end of my create table statement, or if I take that out, that it encounters another CREATE keyword. Both situations cause SQLSyntaxExceptions to be thrown.
So, finally the question...
Is there a way that I can run all my create table statements through one statement execute call? My SQL file is fine if I run it through ij, but through JDBC seems to not work.
Thanks
_________________________________________________________________
Shed those extra pounds with MSN and The Biggest Loser!
http://biggestloser.msn.com/
RE: Reading DDL SQL from JAR
Posted by Magnus Prime <ma...@hotmail.com>.
Yeah.. thats where my thoughts were heading... splitting each CREATE TABLE into its own file, and reading/executing each one at a time...
I was just hoping for another possible way.
> To: derby-user@db.apache.org> From: spam_eater@gmx.net> Subject: Re: Reading DDL SQL from JAR> Date: Tue, 11 Mar 2008 20:13:10 +0100> > Magnus Prime wrote on 11.03.2008 19:05:> > Thanks for the quick reply. I read through that, and I could use the> > runScript method of IJ, but is there nothing inside through standard JDBC> > that allows me to do that? Anything like starting a transactions, running> > them all, then commiting the transaction? Or trying to commit after each> > create table?> > > > The reason I ask, is that as of now, I am using Derby, but I dont want to be> > tied into any DB way of doing things... thats why I was hoping for some> > generic method using standard JDBC only.> > The generic way is to split your script into the individual statements (removing > ; at the end), and then run each statement using executeUpdate() or execute().> > That will work for all DBMS, the CREATE TABLE statements might not work for all > DBMS (because each one has different data types)> > Thomas>
_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan
Re: Reading DDL SQL from JAR
Posted by Thomas Kellerer <sp...@gmx.net>.
Magnus Prime wrote on 11.03.2008 19:05:
> Thanks for the quick reply. I read through that, and I could use the
> runScript method of IJ, but is there nothing inside through standard JDBC
> that allows me to do that? Anything like starting a transactions, running
> them all, then commiting the transaction? Or trying to commit after each
> create table?
>
> The reason I ask, is that as of now, I am using Derby, but I dont want to be
> tied into any DB way of doing things... thats why I was hoping for some
> generic method using standard JDBC only.
The generic way is to split your script into the individual statements (removing
; at the end), and then run each statement using executeUpdate() or execute().
That will work for all DBMS, the CREATE TABLE statements might not work for all
DBMS (because each one has different data types)
Thomas
RE: Reading DDL SQL from JAR
Posted by Magnus Prime <ma...@hotmail.com>.
Thanks for the quick reply.
I read through that, and I could use the runScript method of IJ, but is there nothing inside through standard JDBC that allows me to do that?
Anything like starting a transactions, running them all, then commiting the transaction? Or trying to commit after each create table?
The reason I ask, is that as of now, I am using Derby, but I dont want to be tied into any DB way of doing things... thats why I was hoping for some generic method using standard JDBC only.
> Date: Tue, 11 Mar 2008 10:53:16 -0700> From: bpendleton@amberpoint.com> To: derby-user@db.apache.org> Subject: Re: Reading DDL SQL from JAR> > > Is there a way that I can run all my create table statements through one > > statement execute call? My SQL file is fine if I run it through ij, but > > through JDBC seems to not work.> > Here's some good advice from the last time this was asked:> http://www.nabble.com/sql-format-in-*.sql-files-td15479296.html> > thanks,> > bryan>
_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan
Re: Reading DDL SQL from JAR
Posted by Bryan Pendleton <bp...@amberpoint.com>.
> Is there a way that I can run all my create table statements through one
> statement execute call? My SQL file is fine if I run it through ij, but
> through JDBC seems to not work.
Here's some good advice from the last time this was asked:
http://www.nabble.com/sql-format-in-*.sql-files-td15479296.html
thanks,
bryan