Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

Re: [groovy-user] sql.execute() use of a .sql file problem

Jason mayer

2010-02-05

Replies: Find Java Web Hosting

Author LoginPost Reply
Thanks, that was the problem!

On Fri, Feb 5, 2010 at 3:27 PM, Tim Yates <tim.yates@(protected):
> Think it's the shell redirect "<" which won't work when you try to run it as
> a process (same as with Java)
>
> Think this should work:
>
> def sout = new StringBuffer()
> def serr = new StringBuffer()
> def proc = 'mysql -ubbb -pbbb aaa'.execute()
>
>
> proc.consumeProcessOutput( sout, serr )
> proc.withWriter { writer ->
>   writer << new File( 'createdb.sql' ).text
> }
> proc.waitFor()
> println "sout: $sout"
>
>
> println "serr: $serr"
>
> Tim
>
> On Fri, Feb 5, 2010 at 9:18 PM, Jason Mayer <slamboy@(protected):
>>
>> Groovy Version: 1.7.0 JVM: 1.6.0_18
>> mysql-connector-java-3.1.14-bin.jar
>>
>> import groovy.sql.Sql
>> def getConn() {
>>  def sql = Sql.newInstance("jdbc:mysql://localhost:3306/aaa", "bbb",
>> "bbb", "com.mysql.jdbc.Driver")
>>  sql
>> }
>> def sql = getConn()
>>
>> def setupAllTables(sql) {
>>  "mysql -ubbb -pbbb aaa < createdb.sql".execute().waitFor()  //does
>> nothing, if I run that from the command line it works correctly.
>>  sql.execute("source /my/path/to/the/file/createdb.sql") //fails,
>> works from a mysql prompt
>> }
>>
>> I'm trying to set up a known working set of data in the database
>> during my startup script due to a bug I spent far too long
>> troubleshooting.  How do I do this from within groovy?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.