Wanted: Help switching datasources

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Wanted: Help switching datasources

Siegfried Heintze

I’m trying to use an MS Access database instead of HSQL. Can anyone help me understand what I am doing wrong? I have added MSAccessDataSource.groovy to the conf directory with the contents below. Do I have some metacharacters in my url that are causing problems?

Thanks,

siegfried

 

 

c:\dev\groovy\grails\BoulderProfessionals\grails-app\conf\MSAccessDataSource.groovy

class MSAccessDataSource {

   boolean pooling = true

   String dbCreate = "create-drop" // one of 'create', 'create-drop','update'

   String url = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dev\\groovy\\grails\\BoulderProfessionals\\BoulderProfessionals001.mdb;DefaultDir=;UID=Admin;PWD=;"

   String driverClassName = "sun.jdbc.odbc.JdbcOdbcDriver"

   String username = "Admin"

   String password = ""

}

 

 

C:\dev\groovy\grails\BoulderProfessionals>grails -Dgrails.env=MSAccess run-app

 

Welcome to Grails 0.5.6 - http://grails.org/

Licensed under Apache Standard License 2.0

Grails home is set to: c:\dev\groovy\grails\grails-0.5.6

 

Base Directory: C:\dev\groovy\grails\BoulderProfessionals

java.lang.reflect.InvocationTargetException

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.

java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces

sorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:585)

        at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java

:131)

        at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:160)

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range:

 1

Reply | Threaded
Open this post in threaded view
|

RE: Wanted: Help switching datasources

Siegfried Heintze

I think this is really a groovy, not a grails question. I’m using the java program below, which I just tested with Java 1.6 and MS Access 2003. It runs.

 

Should not this 3 line groovy program run?

 

      println "begin"

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      java.sql.Connection cnn = java.sql.DriverManager.getConnection('jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\Program Files\\Microsoft Office\\Office10\\Samples\\Northwind.mdb;DefaultDir=;UID=Admin;PWD=;');

 

Here is what it prints on my machine:

Caught: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path.  Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

            at MS_JDBC_Demo.run(MS_JDBC_Demo.groovy:9)

            at MS_JDBC_Demo.main(MS_JDBC_Demo.groovy)

Thanks,

Siegfried

 

 

MS_JDBC_Demo.java works:

---------------------------------------------------------------------------------------------

 

import java.sql.*;

import java.util.*;

import java.io.*;

 

/*

 *

 * Begin commands to execute this file using Java with CMD.EXE

 * java -cp . MS_JDBC_Demo "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb;DefaultDir=;UID=Admin;PWD=;" "SELECT FirstName, LastName, HomePhone, Extension FROM EMPLOYEES"

 * End commands to execute this file using Java with CMD.EXE

 *

 */

 

public class MS_JDBC_Demo

{

  public MS_JDBC_Demo(){  }

 

  /** @attribute System.STAThread() */

  public static void main(String[] args)

  {

    PrintStream out = System.out;

    InputStream in = System.in;

    out.println("begin");

    java.sql.Connection cnn;

                       

    try{

      String src = args.length>0?args[0]:"jdbc:odbc:ShopGame",

            sql_stmnt = args.length>1?args[1]:"SELECT * from PRODUCTS",

            class_name = args.length>2?args[2]:"sun.jdbc.odbc.JdbcOdbcDriver";

      out.println("source = "+src);

      out.println("sql = "+sql_stmnt);

      out.println("class = "+ class_name);

      Class.forName(class_name);

      cnn = DriverManager.getConnection(src);

 

      try{

            java.sql.Statement stmt = cnn.createStatement();

            java.sql.ResultSet results = stmt.executeQuery(sql_stmnt);

            java.sql.ResultSetMetaData mdata = results.getMetaData();

           

            // Print out column headers

            int nColumns = mdata.getColumnCount();

            for(int column = 1; column <= nColumns; column++){

              out.print(mdata.getColumnName(column)+"\t");

            }

            out.println();

 

            // Print out the type of each column

            for(int column = 1; column <= nColumns; column++){

              out.print("("+mdata.getColumnTypeName(column)+")\t");

            }

            out.println();

 

            // Print out the label (this seems to be the same as the column name)

            for(int column = 1; column <= nColumns; column++){

              out.print("("+mdata.getColumnLabel(column)+")\t");

            }

            out.println();

 

            // Print out the contents of the column

            while(results.next()){

              for(int column = 1; column <= nColumns; column++){

                out.print(results.getString(column)+"\t");

              }

              out.println();

            }

      }

      catch(java.sql.SQLException e){out.println(e); }

    }

    catch(java.sql.SQLException e){out.println(e); }

    catch(ClassNotFoundException e){ System.out.println(e); }

  }

}

Reply | Threaded
Open this post in threaded view
|

Re: Wanted: Help switching datasources

Guillaume Laforge
Administrator
In reply to this post by Siegfried Heintze
It's more a JDBC question that a Groovy question.
Make sure the JDBC URL is correct.


On 8/18/07, siegfried <[hidden email]> wrote:

>
>
>
>
> I think this is really a groovy, not a grails question. I'm using the java
> program below, which I just tested with Java 1.6 and MS Access 2003. It
> runs.
>
>
>
> Should not this 3 line groovy program run?
>
>
>
>       println "begin"
>
>       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
>
>       java.sql.Connection cnn =
> java.sql.DriverManager.getConnection('jdbc:odbc:DRIVER={Microsoft
> Access Driver (*.mdb)};DBQ=c:\\Program Files\\Microsoft
> Office\\Office10\\Samples\\Northwind.mdb;DefaultDir=;UID=Admin;PWD=;');
>
>
>
> Here is what it prints on my machine:
>
> Caught: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]
> '(unknown)' is not a valid path.  Make sure that the path name is spelled
> correctly and that you are connected to the server on which the file
> resides.
>
>
>
>             at MS_JDBC_Demo.run(MS_JDBC_Demo.groovy:9)
>
>
>
>             at MS_JDBC_Demo.main(MS_JDBC_Demo.groovy)
>
>
>
> Thanks,
>
> Siegfried
>
>
>
>
>
> MS_JDBC_Demo.java works:
>
> ---------------------------------------------------------------------------------------------
>
>
>
> import java.sql.*;
>
> import java.util.*;
>
> import java.io.*;
>
>
>
> /*
>
>  *
>
>  * Begin commands to execute this file using Java with CMD.EXE
>
>  * java -cp . MS_JDBC_Demo "jdbc:odbc:DRIVER={Microsoft Access Driver
> (*.mdb)};DBQ=C:\Program Files\Microsoft
> Office\OFFICE11\SAMPLES\Northwind.mdb;DefaultDir=;UID=Admin;PWD=;"
> "SELECT FirstName, LastName, HomePhone, Extension FROM EMPLOYEES"
>
>  * End commands to execute this file using Java with CMD.EXE
>
>  *
>
>  */
>
>
>
> public class MS_JDBC_Demo
>
> {
>
>   public MS_JDBC_Demo(){  }
>
>
>
>   /** @attribute System.STAThread() */
>
>   public static void main(String[] args)
>
>   {
>
>     PrintStream out = System.out;
>
>     InputStream in = System.in;
>
>     out.println("begin");
>
>     java.sql.Connection cnn;
>
>
>
>     try{
>
>       String src =
> args.length>0?args[0]:"jdbc:odbc:ShopGame",
>
>             sql_stmnt = args.length>1?args[1]:"SELECT * from PRODUCTS",
>
>             class_name =
> args.length>2?args[2]:"sun.jdbc.odbc.JdbcOdbcDriver";
>
>       out.println("source = "+src);
>
>       out.println("sql = "+sql_stmnt);
>
>       out.println("class = "+ class_name);
>
>       Class.forName(class_name);
>
>       cnn = DriverManager.getConnection(src);
>
>
>
>       try{
>
>             java.sql.Statement stmt = cnn.createStatement();
>
>             java.sql.ResultSet results = stmt.executeQuery(sql_stmnt);
>
>             java.sql.ResultSetMetaData mdata = results.getMetaData();
>
>
>
>             // Print out column headers
>
>             int nColumns = mdata.getColumnCount();
>
>             for(int column = 1; column <= nColumns; column++){
>
>               out.print(mdata.getColumnName(column)+"\t");
>
>             }
>
>             out.println();
>
>
>
>             // Print out the type of each column
>
>             for(int column = 1; column <= nColumns; column++){
>
>
> out.print("("+mdata.getColumnTypeName(column)+")\t");
>
>             }
>
>             out.println();
>
>
>
>             // Print out the label (this seems to be the same as the column
> name)
>
>             for(int column = 1; column <= nColumns; column++){
>
>
> out.print("("+mdata.getColumnLabel(column)+")\t");
>
>             }
>
>             out.println();
>
>
>
>             // Print out the contents of the column
>
>             while(results.next()){
>
>               for(int column = 1; column <= nColumns; column++){
>
>                 out.print(results.getString(column)+"\t");
>
>               }
>
>               out.println();
>
>             }
>
>       }
>
>       catch(java.sql.SQLException e){out.println(e); }
>
>     }
>
>     catch(java.sql.SQLException e){out.println(e); }
>
>     catch(ClassNotFoundException e){ System.out.println(e); }
>
>   }
>
> }


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

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

    http://xircles.codehaus.org/manage_email