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 5 of 5

Thread: Trying to connect to a sample Java DB database

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Unhappy Trying to connect to a sample Java DB database

    Please help!
    I am following a learning Java book and trying to access the sample Java DB database with NetBeans but getting this error below. Thanks!

    run:
    Error: Could not find or load main class systablereporter.SysTableReporter
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    Here is the code:

    import java.sql.*;
     
    public class SysTableReporter {
        public static void main(String[] arguments) {
           String data = "jdbc:derby://localhost:1527/sample";
           try (
               Connection conn = DriverManager.getConnection(
                   data, "app", "APP");
               Statement st = conn.createStatement()) {
     
               Class.forName("org.apache.derby.jdbc.ClientDriver");
     
                ResultSet rec = st.executeQuery(
                    "select * " +
                    "from SYS.SYSTABLES " +
                    "order by TABLENAME");
                while(rec.next()) {
                    System.out.println("TABLEID:\t" + rec.getString(1));
                    System.out.println("TABLENAME:\t" + rec.getString(2));
                    System.out.println("TABLETYPE:\t" + rec.getString(3));
                    System.out.println("SCHEMAID:\t" + rec.getString(4));
                    System.out.println();
                }
                st.close();
            } catch (SQLException s) {
                System.out.println("SQL Error: " + s.toString() + " "
                    + s.getErrorCode() + " " + s.getSQLState());
            } catch (Exception e) {
                System.out.println("Error: " + e.toString()
                    + e.getMessage());
            }
        }
    }
    Last edited by matt0605; October 9th, 2012 at 11:32 AM. Reason: missing java tags


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Trying to connect to a sample Java DB database

    Hi matt0605
    Please see the announcements page for the use of code tags and other important information.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Trying to connect to a sample Java DB database

    Edited the post with the code tags!

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,267
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: Trying to connect to a sample Java DB database

    Error: Could not find or load main class systablereporter.SysTableReporter
    It seems your IDE is looking for the class SysTableReporter in the systablereporter package - the class you posted is not defined to be a part of an 'systablereporter' package.

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

    matt0605 (October 10th, 2012)

  6. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Trying to connect to a sample Java DB database

    Thanks, the advice below seemed to do the trick and got rid of the error. Below is what I did.
    "Right click on project node, go to Set configuration, select the main class for the application. Then clean and build."

Similar Threads

  1. Cannot connect Java program to database
    By perry.matthew in forum JDBC & Databases
    Replies: 2
    Last Post: August 29th, 2012, 10:54 AM
  2. connect java to a database
    By ridg18 in forum JDBC & Databases
    Replies: 1
    Last Post: December 25th, 2010, 10:28 AM
  3. Replies: 6
    Last Post: August 18th, 2010, 05:41 PM
  4. Java Swing Tables ( JTable Models ) to connect to Database
    By javaprogrammer in forum JDBC & Databases
    Replies: 0
    Last Post: January 26th, 2010, 03:13 PM
  5. Replies: 0
    Last Post: January 26th, 2010, 03:10 PM

Tags for this Thread