Page 1 of 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    Join Date
    May 2007
    Posts
    139

    Unanswered: run in my PC: Type 1 db driver Access / java[SE1.6] Desktop Applications, what I need

    http://www.paphoscarhire.mobi/odbc-bridge2.jpg
    desktop control panel settings, I have above URL (IMG) Settings
    well, I need to run in my PC: Type 1 db driver Access / java[SE1.6] Desktop Applications, what I need to install ?

    I refer for Type 1, JDBC-ODBC Bridge driver.... Is it needed install and Access 2003 ODBC driver (see URL) ...? How I understand if I already installed it(?) since I do not know ?

    How to load driver in my program ? The below are correct for: Class.forName & DriverManager.getConnection ?
    Code:
     class  ResultSetDemo    {
      public static void main (String  [ ] args)    {
        try {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection conn
              =DriverManager.getConnection("jdbc:odbc:RedWines");  // DSN=RedWines
           Statement  sttmnt  =  conn.createStatement (  );
    I GET ERROR !
    Code:
     C:\Users\User\Documents\TextBooks Data Files\The Web Warrior Guide to Web Database Technolo
    gies, 1st Edition\extract\Chapter06\Chapter>java ResultSetDemo
    [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM claus
    e.
            at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
            at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
            at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
            at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
            at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
            at ResultSetDemo.main(ResultSetDemo.java:10)
    
    
    C:\Users\User\Documents\TextBooks Data Files\The Web Warrior Guide to Web Database Technolo
    gies, 1st Edition\extract\Chapter06\Chapter>

  2. #2
    Join Date
    Aug 2009
    Posts
    68
    DriverManager call is correct.
    Did you configure an ODBC source named RedWines in the system ? Having only an Access database named RedWines is not enough.

    HTH
    Laurent

  3. #3
    Join Date
    May 2007
    Posts
    139

    I havn't installed JDBC-ODBC Bridge driver or even ODBC driver for java

    See the URL, I do not know if I have installed JDBC-ODBC Bridge driver or even ODBC driver for java, where found, and how understand if I have them ?
    I make DSN as URL shows but I sure I do not have drivers where found themselves and installation instructions?

  4. #4
    Join Date
    Aug 2009
    Posts
    68
    sun.jdbc.odbc.JdbcOdbcDriver is in your classpath, if not, "Class.forName()" would have thrown a ClassNotFoundException. This call looks doing nothing, but instructs the class loader to fetch the desired class.
    The problem is with "jdbcdbc:RedWines" in [ODBC Microsoft Access Driver] Syntax error in FROM clause.

    So it's not a java problem but an error at the end of your connection string. Maybe there should be a login/password information here, or anything of the like.

    Microsoft error messages are often confusing, so I suggested to verify if ODBC source is really available first.
    I have no working example by hand today, but I'll fetch this on Monday.
    LS

  5. #5
    Join Date
    May 2007
    Posts
    139
    I am almost sure I have not installed JDBC-ODBC Bridge driver or even ODBC driver for java, where found, online to install them...? for Access 2003...

  6. #6
    Join Date
    Aug 2009
    Posts
    68
    Hi...
    You should look at:
    http://java.sun.com/j2se/1.3/docs/gu...ridge.doc.html
    As they say, the JDBC-ODBC bridge driver you try to use is a part of java 2 SDK, so you already have it (somewhere in your development IDE).

    Then, you must configure an ODBC data source in your system: Control Panel/System Administration Tools/Data Sources (ODBC).
    Add a new source pointing to your Access database file using ODBC Access driver.

    HTH
    Laurent

  7. #7
    Join Date
    May 2007
    Posts
    139
    ODBC Access driver must be installed or and this installed along with Access ? how understand if I have it or not visually in windows ? For sure I only ODBC MySQL installed, well how understand about Access ? I run VISTA HOME PREMIUM ...

  8. #8
    Join Date
    Aug 2009
    Posts
    68
    Quote Originally Posted by lse123 View Post
    ODBC Access driver must be installed or and this installed along with Access ? how understand if I have it or not visually in windows ?
    None of the two. It's a part of your Windows system. Go to the ODBC configuration panel, and you shall find it here in the drivers list (along with many others).
    Quote Originally Posted by lse123 View Post
    For sure I only ODBC MySQL installed, well how understand about Access ? I run VISTA HOME PREMIUM ...
    The problem is to declare a data source (DSN) not loading or finding drivers which already are there.
    If you don't want to use a system or user DSN, you can try this:
    Code:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/temp/thebase.mdb";
    String user = "user";
    String pass = "pass";
    Connection connection = DriverManager.getConnection(url,user,pass);
    Of course, you have then to replace "C:/temp/thebase.mdb" with the path to an existing Access file.

    Laurent

  9. #9
    Join Date
    May 2007
    Posts
    139
    You mean ODBC Access driver is an Additional Installation, so if I do not have, I must install ? If I do not have it, where it can be found ?

  10. #10
    Join Date
    May 2007
    Posts
    139
    ODBC Access driver is NOT ONLY for java, correct ?

  11. #11
    Join Date
    Aug 2009
    Posts
    68
    Yeah, it's a standalone thing in the system (a JET engine) which provides ODBC access (without cap). Excel spreadsheets have one too.
    You can use it with any software knowing ODBC which is a general way to manage datasources.
    IMO, you need not to fetch or install anything (except, maybe, a DSN). There's only something wrong in your connection string (url + credentials).

    Laurent

  12. #12
    Join Date
    May 2007
    Posts
    139
    problem solved ...(first is wrong since must be space between WINES" + "WHERE...
    ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES" + "WHERE ...
    ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES " + "WHERE ...

    ACCESS ODBC Driver usually ships with office(no need install) ?
    I used Success:
    Connection conn=DriverManager.getConnection("jdbcdbc:RedWines");
    well the below you refer also is valid, and used when no DSN(or must exist?)??? What is DBQ?

    String url= "jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=C:/temp/thebase.mdb";
    String user = "user";
    String pass = "pass";
    Connection connection = DriverManager.getConnection(url,user,pass);

  13. #13
    Join Date
    Aug 2009
    Posts
    68
    Quote Originally Posted by lse123 View Post
    problem solved ...(first is wrong since must be space between WINES" + "WHERE...
    ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES" + "WHERE ...
    ResultSet rs = sttmnt.executeQuery("SELECT * FROM WINES " + "WHERE ...
    I'm happy to hear that. But... you never posted this query !
    Quote Originally Posted by lse123 View Post
    I used Success:
    Connection conn=DriverManager.getConnection("jdbcdbc:RedWines");
    well the below you refer also is valid, and used when no DSN(or must exist?)???
    I don't think a DSN must exist.

    Regards
    Laurent

  14. #14
    Join Date
    May 2007
    Posts
    139
    I have another point: (I use DSN) I add records FROM FILE.txt and other case I add TABLES but this do not seem in Access, neither seem to other database driver java files(listing of records)... well? I add like:

    public static void main(String [ ] args) {
    String fileName = "";
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Driver
    Connection conn = DriverManager.getConnection
    ("jdbcdbc:RedWines");
    Statement sttmnt = conn.createStatement( // Scrollable
    ResultSet.TYPE_SCROLL_INSENSITIVE, // pointer
    ResultSet.CONCUR_READ_ONLY );


    if (args.length > 0)
    fileName = args[0]; // args[0] from command line
    else {
    System.out.println("Must supply file name – rerun!");
    System.exit(0);
    }
    // Create a new table. Populate it with records from input file.
    sttmnt.executeUpdate("DROP TABLE WINES");
    BufferedReader inputFile = new BufferedReader(
    new FileReader(fileName + ".txt"));
    String recordInput = inputFile.readLine(); // Read 1st rec
    String sqlCommand = "CREATE TABLE WINES" +
    "(" + recordInput + ")"; // Create SQL command
    System.out.println(sqlCommand);
    sttmnt.executeUpdate(sqlCommand); // Execute SQL command

    while ((recordInput = inputFile.readLine())!= null) // Read
    {
    sqlCommand = "INSERT INTO WINES " + // Build SQL
    "VALUES (" + recordInput + ")"; // statement
    System.out.println("SQL statement:" + sqlCommand);
    System.out.println("Record Added.");
    int result = sttmnt.executeUpdate(sqlCommand); // Execute
    } // end of while

  15. #15
    Join Date
    Aug 2009
    Posts
    68
    Quote Originally Posted by lse123 View Post
    I have another point: (I use DSN) I add records FROM FILE.txt and other case I add TABLES but this do not seem in Access, neither seem to other database driver java files(listing of records)... well? I add like:
    Your code looks correct, but I don't understand the sentence: "this do not seem in Access". Does this means it doesn't work in Access ?
    If so, you cannot hope I could reply anything without further details.
    What did you put in your file ?
    What's the result of the execution in Access ?
    Did you get any errors ? (I suppose there is a "catch" balancing the "try" and hope it displays something).

    BTW, I would *never* put DDL statements in a plain text file.

    Laurent

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •