Results 1 to 6 of 6
  1. #1
    JavaDreams is offline Member
    Join Date
    Jan 2011
    Posts
    18
    Rep Power
    0

    Default Database connection for server

    I have a hosting on net, and have created a database using phpMyadmin provided in cpanel.
    so i make a code in netbeans and write the connection statement.


    Java Code:
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String url = "jdbc:mysql://www.Mywebsite.com:2082/My_TestDB";
    Connection con = DriverManager.getConnection(url,"My_userid","Password");
    Now when running the code on netbeans and submiting values to database,
    it gives error.
    Java Code:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Please tell me what are the things i am doing wrong.
    I am also confused with the installation of connector J, on my windows, i mean i have run the Jar but nothing happers, does it workes silently??
    Last edited by JavaDreams; 03-10-2011 at 11:16 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    You don't install it.
    You need to include the jar file in your runtime classpath, so the jar needs to be included as part of your project in Netbeans.

    All that error means is that Java can't find the class because you haven't added the connectorJ jar to your project.

  3. #3
    JavaDreams is offline Member
    Join Date
    Jan 2011
    Posts
    18
    Rep Power
    0

    Default

    @ Tolls
    I have added the jar folder of connector j, in my project but it's still giving the same exception!!

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    Then it's not added correctly.
    It needs to be available at runtime.
    I can't remember exactly what needs doing for Netbeans, but it should be simply adding it to the runtime path.

  5. #5
    JavaDreams is offline Member
    Join Date
    Jan 2011
    Posts
    18
    Rep Power
    0

    Default

    yes i was adding the whole folder, but then i added the main Jar file, ok that issue is solved.
    Thankyou Tolls :)
    One more question, can i access the database on my website, from netbeans, because my website does not provide Java on their servers.And they said you can access it at localhost at the specified port.

    So Any suggestions ?? :)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    If they say access at localhost:<port> then that (to me) says they haven't opened it up to external access. Only via your website.
    MySQL needs to be informed where login attempts are allowed to come from. Some hosts will allow you to set that, but others prefer to keep it locked down.

    I'd look at your MySQL control panel (whatever it's called) and see what options you have.

Similar Threads

  1. connection to database
    By buston01 in forum JDBC
    Replies: 4
    Last Post: 02-21-2010, 01:32 AM
  2. Replies: 0
    Last Post: 12-01-2009, 10:01 PM
  3. getting database connection
    By ravidasineni in forum AWT / Swing
    Replies: 0
    Last Post: 11-27-2009, 04:33 AM
  4. getting database connection
    By ravidasineni in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 02:01 AM
  5. database connection in jsf
    By Srikala in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 10-06-2008, 06:53 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
  •