Results 1 to 5 of 5
  1. #1
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default MySql5.1 and NetBeans

    Hi, I dont know if Im on the right section of this forum. I am using NetBeans and MySql. MySql is located on other machine. Now I already try to connect through services tab, I add drivers path and enter needed information and it was able to connect. Now I am trying it through code. Do I have to set MySql Connector/J path?
    Java Code:
    public class Connect extends javax.swing.JFrame {
        public Connect() {
            initComponents();
        }
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Connect().setVisible(true);
                }
            });
    
               Connection conn = null;
    
               try
               {
                   String userName = "MyPC";
                   String password = "MyPassWord";
                   String url = "jdbc:mysql://OtherPC:3306/test";
                   Class.forName ("com.mysql.jdbc.Driver").newInstance ();
                   conn = DriverManager.getConnection (url, userName, password);
                   System.out.println ("Database connection established");
               }
               catch (Exception e)
               {
                   System.err.println ("Cannot connect to database server");
               }
               finally
               {
                   if (conn != null)
                   {
                       try
                       {
                           conn.close ();
                           System.out.println ("Database connection terminated");
                       }
                       catch (Exception e) {}
                   }
               }
        }

    Thanks in advance,
    geje
    Last edited by mine0926; 05-19-2010 at 03:02 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    From Output window it printsCannot connect to database server

    I was able to solve it by copying MySql Connector/J to:
    jdk1.6.0_18\jre\lib\ext

    Thanks,
    geje

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Is this the right thing to do?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,012
    Rep Power
    20

    Default

    No.
    You should have no need to copy stuff into that directory.
    You should add the jar to your project libraries.
    There'll be an option somewhere (or simply look it up in the help pages).

Similar Threads

  1. Netbeans Help
    By MuslimCoder in forum New To Java
    Replies: 1
    Last Post: 11-07-2009, 02:23 AM
  2. netbeans
    By Nishanthi in forum New To Java
    Replies: 11
    Last Post: 10-02-2009, 09:29 AM
  3. Netbeans IDE 6.5
    By Manfizy in forum NetBeans
    Replies: 5
    Last Post: 06-07-2009, 02:24 AM
  4. cannot run web app with Netbeans
    By CirKuT in forum New To Java
    Replies: 5
    Last Post: 10-28-2008, 03:48 PM
  5. netbeans
    By sweet angle in forum NetBeans
    Replies: 1
    Last Post: 08-05-2008, 04:06 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
  •