/** * Simple example of using FileMaker Pro from within java via JDBC * * To set up your FileMaker Pro database to be accessible * through ODBC (and thus JDBC), see "Sharing FileMaker Pro data via ODBC" * in FileMaker's help file. Note that you do NOT need FileMaker Server for this. */ import java.lang.*; import java.sql.*; class JDBCFilemakerExample { public static void main(String argv[]) { // Construct the database address // The JDBC URL is in the form: // jdbc:odbc:YourODBCDataSourceName // "odbc:" tells java to use the JDBC to ODBC bridge driver // YourODBCDataSourceName is the name of the ODBC data source you're accessing String dbaseURL = "jdbc:odbc:filemaker"; // Make the database connection Connection dbConnection = null; Statement query = null; // Load the JDBC to ODBC driver try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } // Now we get to work! try { // Create a database connection dbConnection = DriverManager.getConnection(dbaseURL, "null", "null"); // Create a statement and execute the SQL query query = dbConnection.createStatement(); } catch (SQLException e) { System.out.println("Error connecting to dbase."); e.printStackTrace(); //System.exit(1); } ResultSet results = null; try { // When working with FileMaker, there's a good chance that rows, collums, and // especially tables will have spaces in them. If they do, put them in // quotes like you see here. Each of your Filemaker documents appears as it's own table // with the file extension stripped off. So the database file on my hard drive named // "Sales Reports.fp5" shows up through ODBC/JDBC as a table named "Sales Reports". results = query.executeQuery("SELECT `Invoice ID`, `Company Name` from `Sales Reports`"); // Iterate through the results and print them to standard output while (results.next()) { String fname = results.getString("Invoice ID"); String lname = results.getString("Company Name"); System.out.println("Found user \"" + fname + " " + lname + "\""); } } catch (SQLException e) { System.out.println("Error retrieving data from database."); e.printStackTrace(); //System.exit(1); } } }