Results 1 to 5 of 5
  1. #1
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default connecting a java application to a DB in netbeans

    hello

    i am writing an application that can access the database.

    compiling and running the application in the command prompt is easy. i can easily access the databse and update it and do anything with it..

    but when i go use the netbeans IDE, it would always give me exceptions..

    codes like Class.forName("org.apache.derby.jdbc.EmbeddedDrive r"); wont find the said driver and it also gives me the "ClassNotFoundException"

    here is what i wrote..


    import java.util.Properties;
    import java.sql.*;

    public class Main extends Frame implements ActionListener
    {

    void connector() throws SQLException, ClassNotFoundException
    {
    Class.forName("org.apache.derby.jdbc.EmbeddedDrive r");

    Properties props = new Properties();

    props.put("user", "simon");
    props.put("password", "simon");

    Connection con = DriverManager.getConnection("jdbc:derby:stocks",pr ops);

    }
    public static void main(String[] args)
    {
    Main copy = new Main();
    }

    public void actionPerformed(ActionEvent e)
    {
    String args = e.getActionCommand();

    if(args=="connect")
    {
    try {
    connector();
    }

    catch (SQLException ex)
    {
    System.out.println("wrong");
    }

    catch (ClassNotFoundException ex)
    {
    System.out.println("wrong");
    }

    }
    }

    }

    aside from these i have also created the database that is running in an embeddeddriver

    im also confused with it, when you right click the database node it will show you the option connect, so where does it connect? to my application?

    and do i really have to write the code Connection con = DriverManager.getConnection("jdbc:derby:dbName");

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    You haven't registered the Derby JAR in your project, so it is not appearing on the classpath. I'm surprised your code compiles in Netbeans...

  3. #3
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default ei..

    tnx for the post mr.steve,

    i thought that the netbeans already have these libraries because you can create a db from the services node and you can do it with less typing but i knew that you should still add a library..

    anyway, thanx for the post.
    appreciate it

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    Thanks for the kind reply. I learned everything I know by beating my head against that wall at least once...

  5. #5
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default haha!!

    i also do some stupid things like that when i get frustrated., now i know that i am not alone hehe..

    thanks to these forums and posters like you it would lessen such things from happening

Similar Threads

  1. problems with connecting to Oracle DB in NetBeans
    By m16k2002 in forum Web Frameworks
    Replies: 6
    Last Post: 03-25-2009, 11:14 AM
  2. Connecting c with java
    By khajalid in forum Networking
    Replies: 6
    Last Post: 12-10-2008, 10:35 PM
  3. Connecting c with java
    By khajalid in forum Advanced Java
    Replies: 4
    Last Post: 09-11-2008, 05:47 AM
  4. Replies: 0
    Last Post: 08-07-2007, 08:01 AM
  5. Replies: 0
    Last Post: 07-31-2007, 12:13 AM

Posting Permissions

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