Results 1 to 7 of 7
  1. #1
    scchia is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Unhappy hello the community & mysql connecting problems

    Hello,i am forty+ of age and in healthcare profession.
    past couple of years, i programmed in php(LMAP).
    recently i thought of do away with php and replace with java.
    i am using Mandriva spring 2008,jvm(jdk1.6.0.10),netbeans ide 6.1.(usr/local)
    i had collected couples of tutorials and sample codes from the net.
    general java programming is interesting and powerful.
    i ran intranet database application with 2pcs (LMAP).
    i had tried to connect to mysql database by using mysql conector/J driver->
    localhost:3306/db (user/passwd) but return connection fails,similar failure by encountered by using odbc driver (netbeans ide env / scripting).
    the only successful connection is with jdbc:derby driver(sample/travel db).
    Hey!guys,i really with helps.
    thank you.

  2. #2
    scchia is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default

    a piece code from prfalco::
    Hello:
    I have this code to connect to a MySQL database:

    package paquetedb;

    import java.sql.*;

    public class PruebaDB {

    public static void main(String[] args) {
    Connection con = null;
    try{
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","xyz001");
    if (!con.isClosed()){
    System.out.println("conexión exitosa a MySQL");
    }
    }catch(Exception e){
    System.err.println("Excepción: " + e.getMessage());
    }finally{
    try{
    if (con != null)
    con.close();
    } catch(SQLException e){}
    }
    }

    }
    return error !!
    from JAdmin :
    You need to have MySQL related files in your classpath. Download mysql-connector-java-3.1.14-bin.jar and add to the classpath.
    my question : what is classpath and howto?
    thank you.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You mentioned 2 pcs. Is the DB on the same machine from which you strated the JAva application? If not, you can't, of course, use localhost.

    Other than that, the "newInstance()" on the Class.forName call is completely useless. All you need is the Class.forName("driver"), not newInstance().

    Also, knowing what exception you are getting, including the full stacktrace, would be extremely helpful in attempting to track down your problem.

    Add e.printStacktrace() to your catch block, not just e.getMessage().

  4. #4
    scchia is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Unhappy still not communicable

    thank you for the reply.
    the 2 pcs have 2 sets of mysql databases,one for backup,both are running.
    i downloaded the newest mysql connecotr/j 5.1.6 driver and install in usr/local.
    i set pathclass with netbeans and use side by side with the one supply by netbeans,but both returned communication link error.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Okay, then, like I said, what exception. The full stack trace please and the relevant code.

  6. #6
    Liaoxy is offline Member
    Join Date
    Jul 2008
    Location
    Chendu of China
    Posts
    3
    Rep Power
    0

    Default

    from your code and description I think the most possible reason is you did'nt add the driver jar to the right classpath,I use eclipse ,I had not used netbean

  7. #7
    scchia is offline Member
    Join Date
    Jul 2008
    Posts
    10
    Rep Power
    0

    Default

    i had thrown mandriva away and install fedora-8.
    mysql up and run as aspected.
    netbeans build-in mysql connector/j detected mysql databases
    and expand the (nodes) tables easily.
    i think the flaw is with mandriva spring 2008.
    thank you.
    see you guys in future.

Similar Threads

  1. problems with connecting to Oracle DB in NetBeans
    By m16k2002 in forum Web Frameworks
    Replies: 6
    Last Post: 03-25-2009, 10:14 AM
  2. Replies: 0
    Last Post: 04-22-2008, 11:57 AM
  3. problem in connecting to mysql database
    By nancyv in forum Java Servlet
    Replies: 6
    Last Post: 04-02-2008, 11:33 AM
  4. Replies: 0
    Last Post: 08-07-2007, 07:01 AM
  5. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 12:36 PM

Posting Permissions

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