Complete Example
This section shows the complete program to create, update, and select from a database using JDBC. A longer version of this code comes with the Mckoi database and can be found in directory c:\mckoi\demo\simple
. The code has been split into two programs there for convenience, one to create the tables, and one to query them.
/** * Demonstrates how to use JDBC. */import java.sql.*;public class Example { public static void main(String[] args) { // Register the Mckoi JDBC Driver try { Class.forName("com.mckoi.JDBCDriver"); } catch (Exception e) { System.out.println("Can't load JDBC Driver. " + "Make sure classpath is correct"); return; } // This URL specifies we are creating a local database. The ...
Get Just Java™ 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.