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

Thread: problem in Derby embedded database connection

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default problem in Derby embedded database connection

    Hello Java forum members !

    Firstly please forgive my ignorance , I am beginner in java database programming.
    I cannot make connection to Embedded derby database. This is what I did

    1)created derby database with one table using netbeans 7.1.2. And inserted some data in that table via sql command

    Now I want to read data from this database's table from a java class but I am getting this message when I run

    Errorjava.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver

    here is my code of the class

     
     
    package mypackage;
     
    import java.sql.*;
     
     
     
    public class DbConnection {
     
        Connection con;
        Statement st;
        ResultSet rs;
     
        public DbConnection() {
            connect();
     
        }
        public void connect() {
            try{
     
                String driver = "jdbc:derby:fida;user=scott;password=tiger";
                Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
     
     
                con= DriverManager.getConnection(driver);
                st=con.createStatement();
                String sql = "select * from APP.STUDENT";
                rs = st.executeQuery(sql);
                while(rs.next())
                {
                    System.out.println(rs.getInt("ID"));
                    System.out.println(rs.getString("name"));
                    System.out.println(rs.getString("fname"));
     
                }
     
            }catch(Exception ex){
                System.out.println("Error"+ex);
            }
     
     
        }
        public static void main (String args[]){
            new DbConnection();
        }
     
    }


    Please help me out , and forgive my ignorance.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: problem in Derby embedded database connection

    Where is the missing class? The java program can not find it.
    If it is in a jar file, put the jar file on the classpath.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problem in Derby embedded database connection

    Hi Norm ! Thank you for the reply , I didn't include the jar file. Now problem is solved . Can you please send me links of good sources of learning material on jdbc and also on derby. I am newbie although I have strong java OOP concepts. I want to learn database programming in java.

    Forgot to mention I also know SQL.

    Please help .

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: problem in Derby embedded database connection

    Sorry, I don't have any links for DB stuff.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problem in Derby embedded database connection

    hi Norm,
    how are you doing? i found another problem hopefully will solve it, i am trying to connect embedded database but can't.
    the error i get is "java.sql.SQLSyntaxErrorException: 'DROP TABLE' cannot be performed on 'APP.TABEL1' because it does not exist.
    and i have created this table in database.
    here is my code
     
    package db;
     
    import java.sql.*;
    public class Derby {
        public static void main(String[] args) {
            Connection con = null;
            Statement st = null;
     
            String url = "jdbc:derby:javaDB";
     
            try
            {
     
                con = DriverManager.getConnection(url);
                st = con.createStatement();
                st.executeUpdate("drop table app.tabel1");
            }
            catch(Exception e)
            {
                System.out.println(e);
            }   
        }
    }

    Thanks

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: problem in Derby embedded database connection

    Sorry, I don't know anything about SQL
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problem in Derby embedded database connection

    its okay dear,
    and thanks for your response

Similar Threads

  1. [SOLVED] database connection problem adding,deleting,updating,selecting :(
    By jabaman in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 6th, 2012, 01:05 PM
  2. MS Access database connection problem
    By faysal40 in forum JDBC & Databases
    Replies: 1
    Last Post: August 29th, 2011, 01:22 AM
  3. Managing an embedded database
    By jstn455 in forum JDBC & Databases
    Replies: 1
    Last Post: April 24th, 2011, 10:06 AM
  4. Replies: 0
    Last Post: April 3rd, 2011, 10:58 AM
  5. How to deploy derby database?
    By Muaz_Sh in forum JDBC & Databases
    Replies: 8
    Last Post: March 17th, 2011, 09:23 AM