AnsweredAssumed Answered

Getting started with JDBC--simple sample java program?

Question asked by wdockery on Oct 9, 2012
Latest reply on Oct 9, 2012 by davidanders

Title

Getting started with JDBC--simple sample java program?

Post

     Hi, question about my first foray into JDBC:

     Background:  FM Pro Advanced 11, intermediate user, not a Java programmer, Mac OS 10.7, latest Java update installed, downloaded FM JDBC driver (fmjdbc.jar) from FM website, copied to /Library/Java/Extensions as instructed on FM website.

     Tried to copy and compile the short Java program in the FM ODBC/JDBC manual to confirm connectivity, (BTW, why would that manual have a sample program with the message "Note This example is not meant to be compiled."--Not nice!), and got an error.

     Source code:

     import java.sql.*;
     class FMPJDBCTest
     {
     public static void main(String[ ] args)
     {
     // register the JDBC client driver
     try {
     Driver d = (Driver)Class.forName("com.filemaker.jdbc.Driver").newInstance();
     } catch(Exception e) {
     System.out.println(e);
     }
     // establish a connection to FileMaker
     Connection con;
     try {
     con = DriverManager.getConnection("jdbc:filemaker://127.0.0.1/locations Converted","admin", "admin");
     } catch(Exception e) {
     System.out.println(e);
     }
     // get connection warnings
     SQLWarning warning = null;
     try {
     warning = con.getWarnings();
     if (warning == null) {
     System.out.println("No warnings");
     return;
     }
     while (warning != null) {
     System.out.println("Warning: "+warning);
     warning = warning.getNextWarning();
     }
     } catch (Exception e) {
     System.out.println(e);
     }
     } }

     Compile error:

     javac ~/Desktop/FMPJDBCTest.java
     /Users/wdockery/Desktop/FMPJDBCTest.java:22: variable con might not have been initialized
     warning = con.getWarnings();
       ^

     Advice on how to proceed?  Thanks--

Outcomes