/* * [ConnectJDBCDerbyClient.java] * * Summary: demonstrate the how to connect to a Derby Database via JDBC and the client driver. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2007-09-26 */ package com.mindprod.example; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import static java.lang.System.*; /** * demonstrate the how to connect to a Derby Database via JDBC and the client driver. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2007-09-26 * @since 2007-09-26 */ @SuppressWarnings( { "WeakerAccess", "UnusedDeclaration" } ) public class ConnectJDBCDerbyClient { /** * which database */ private static final String DATABASENAME = "SQUIRRELS"; /** * class name of the JDBC driver. Must be accessible on the classpath. * Mac OS may be missing the Derby driver in the JDK distribution. * Use the one that comes with NetBeans. * /Applications/NetBeans/glassfish-v2.1/javadb/lib */ private static final String DRIVERCLASSNAME = "org.apache.derby.jdbc.ClientDriver"; /** * access PASSWORD */ private static final String PASSWORD = "sesame"; /** * basic URL to access the database */ @SuppressWarnings( { "ConstantNamingConvention" } ) private static final String URL = ""; /** * login name of user */ private static final String USERNAME = "charlie"; /** * The connection. Handle to the database */ @SuppressWarnings( { "FieldCanBeLocal", "UnusedDeclaration" } ) private static Connection conn; /** * connect to the derby database */ private static Connection connect() throws SQLException { try { Class.forName( DRIVERCLASSNAME ); } catch ( Exception e ) { err.println( "can't load Derby Client JDBC driver: " + e.getMessage() ); } return DriverManager.getConnection( "jdbc:derby://localhost:1527/" + DATABASENAME + ";create=true;", USERNAME, PASSWORD ); } /** * initialise the database * * @param args not used */ public static void main( String[] args ) throws SQLException { conn = connect(); // ... conn.close(); } }