Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java app with Netbeans and Derby database

  1. #1
    Junior Member Kakashi's Avatar
    Join Date
    Oct 2009
    Posts
    29
    My Mood
    Confused
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Java app with Netbeans and Derby database

    Ok so I have a database in netbeans following this tutorial
    Working with the Java DB (Derby) Database - NetBeans IDE 6.8 Tutorial
    and this worked great I got the dtabase up and running and its connected and has 2 rows in the book talbe and two rows in the patron table. I can view the data by right clicking the table and selecting view data and that works so the data is in the talbe and the little connection sysble shows that it is connected. The problem is when I try to connect to the database with the java app that does not work. It says no suitable drive found
    java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/BOOK;jdbc.username=Gus

    Here is the java app:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
     
    class TestDB
    {
       public static void main(String args[])
       {
          try
          {
             runTest();
          }
          catch (SQLException ex)
          {
             for (Throwable t : ex)
                t.printStackTrace();
          }
          catch (IOException ex)
          {
             ex.printStackTrace();
          }
       }
     
       /**
        * Runs a test by creating a table, adding a value, showing the table contents, and removing the
        * table.
        */
       public static void runTest() throws SQLException, IOException
       {
          Connection conn = getConnection();
          try
          {
             Statement stat = conn.createStatement();
     
             stat.executeUpdate("CREATE TABLE Greetings (Message CHAR(20))");
             stat.executeUpdate("INSERT INTO Greetings VALUES ('Hello, World!')");
     
             ResultSet result = stat.executeQuery("SELECT * FROM Greetings");
             if (result.next())
                System.out.println(result.getString(1));
             result.close();
             stat.executeUpdate("DROP TABLE Greetings");
          }
          finally
          {
             conn.close();
          }
       }
     
       /**
        * Gets a connection from the properties specified in the file database.properties
        * @return the database connection
        */
       public static Connection getConnection() throws SQLException, IOException
       {
          Properties props = new Properties();
          FileInputStream in = new FileInputStream("database.properties");
          props.load(in);
          in.close();
     
          String drivers = props.getProperty("jdbc.drivers");
          if (drivers != null) System.setProperty("jdbc.drivers", drivers);
          String url = props.getProperty("jdbc.url");
          String username = props.getProperty("jdbc.username");
          String password = props.getProperty("jdbc.password");
     
          return DriverManager.getConnection(url, username, password);
       }
    }
    Thanks for any help on this


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java app with Netbeans and Derby database

    You need to add the driver to your classpath. See http://www.javaprogrammingforums.com...html#post20626

  3. #3
    Junior Member Kakashi's Avatar
    Join Date
    Oct 2009
    Posts
    29
    My Mood
    Confused
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Java app with Netbeans and Derby database

    I thought I had the drivers but I think not. Also, I am running the database in netbeans should I run that from the command line?
    Second, place the downloaded jar file on the classpath of the program. Is there a way of doing this in Netbeans?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java app with Netbeans and Derby database

    I don't use Netbeans so wouldn't be the best person to ask. That being said I'm sure there are docs elsewhere which describe the process of adding an external library to the classpath.

  5. The Following User Says Thank You to copeg For This Useful Post:

    Kakashi (April 12th, 2011)

Similar Threads

  1. How to deploy derby database?
    By Muaz_Sh in forum JDBC & Databases
    Replies: 8
    Last Post: March 17th, 2011, 09:23 AM
  2. calling a java a class connected to derby from a batch file
    By Reem in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 03:01 PM
  3. Java (Derby) Help
    By Neon612 in forum JDBC & Databases
    Replies: 3
    Last Post: August 19th, 2010, 08:40 PM
  4. org.apache.derby does not exist?
    By disclaimer in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 30th, 2010, 04:58 PM
  5. Database connection using NetBeans
    By jcc285 in forum Java IDEs
    Replies: 6
    Last Post: June 9th, 2009, 03:23 AM