Results 1 to 3 of 3
  1. #1
    silencecm is offline Member
    Join Date
    Jun 2012
    Nova Scotia, Canada
    Rep Power

    Question Correct Driver for JDBC Derby

    Hi all, I'm new to the forum. I didn't plan on jumping right in and asking for help : ( Thanks in advance for any help!
    I'm starting my second year of web development in September, and I decided to work on a personal project over the summer.
    I have Java experience and a bit of Oracle SQL but have never worked with a JDBC.

    Here is my attempt to pull data:

    Using Netbeans 7.1, I created a sample database with a few entries of liquor names (no username or password).
    The table is called MIXES. Sorry If I omitted any pertinent information here.

    I need help choosing and installing the appropriate driver for this jdbc (I think).

    Java Code:
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    public class JavaDBTest {
        // database URL
        static final String DATABASE_URL = "jdbc:derby://localhost:1527/liquor";
        // launch the application
        public static void main(String[] args) {
            // manage the connection
            Connection connection = null;
            // query statament
            Statement statement = null;
            //manage the results
            ResultSet resultSet = null;
            //connect to database and query the database
            try {
                //establish connection to database
                connection = DriverManager.getConnection(DATABASE_URL, "", "");
                //create Statement for querying databse
                statement = connection.createStatement();
                //process query results
                ResultSetMetaData metaData = resultSet.getMetaData();
                int numberOfColumns = metaData.getColumnCount();
                System.out.println("Liquors in Database:\n");
                for (int i=1; i<=numberOfColumns; i++) {
                    System.out.printf("%-8s\t", metaData.getColumnName(i));
                }// end for
                while ( {
                    for (int i=1; i<=numberOfColumns; i++) {
                        System.out.printf("%-8s\t", resultSet.getObject(i));
                    } //end for
                } // end while
            } // end try
            catch (SQLException sqlException) {
            } //end catch
            //ensure resultSet, statment and connection are closed
            finally {
                try {
                } //end try
                catch (Exception exception) {
                } //end catch  
            }//end finally
        }//end Main
    }//end Class JavaDBTest

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power

    Default Re: Correct Driver for JDBC Derby

    Derby JDBC driver class can be found in the derby.jar file packaged with the database. Before create a connection to the database you'll need to register the driver class class so that it can be picked-up by the DriverManager to create a connection to the database. You can do it with the following snippet:

    Java Code:

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Correct Driver for JDBC Derby

    If they're using Java 6+ then there's no need to register the driver.
    That's all done automagically these days.
    Just make sure the jar is on the runtime classpath.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 03-03-2012, 02:01 AM
  2. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Advanced Java
    Replies: 5
    Last Post: 11-22-2011, 05:54 PM
  3. Replies: 1
    Last Post: 09-12-2011, 10:42 AM
  4. problem with derby driver
    By vitaly87 in forum New To Java
    Replies: 0
    Last Post: 07-16-2011, 01:47 PM
  5. JDBC Driver
    By Ursula in forum New To Java
    Replies: 6
    Last Post: 08-23-2010, 05:41 PM

Posting Permissions

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