How to make connection from Java to MySQL?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WilHob
    New Member
    • May 2007
    • 5

    How to make connection from Java to MySQL?

    Hello:
    I can not make connection to MySQL from Java.

    I set System Variable CLASSPATH to:
    C:\MySQL\mysql-connector-java-5.0.5\mysql-connector-java-5.0.5-bin.jar
    ...
    Then registered Driver:
    ...
    try {
    Class.forName(" com.mysql.jdbc. Driver").newIns tance();
    }
    ...
    Made Connection:
    Connection conn =
    DriverManager.g etConnection("j dbc:mysql://localhost:3306/test","User","P sw");
    ...
    And got Error Message:

    SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test

    How to make connection from Java to MySQL?
    Thanks
  • blackflicker
    New Member
    • May 2007
    • 4

    #2
    Hello WilHob,

    It is really weird. Are you sure that there is a database like that and have you tried to put the .jar into the same directory with your "standalone " application (if it's not a standalone application then you have to put it to the related folder) and adding the path to the classpath. Or/And you may try to pass the class path to the java executable in a parameter too; for just trying. Like:

    java -classpath t1.jar;t2.jar myapp

    Good luck!
    Last edited by blackflicker; May 26 '07, 08:47 AM. Reason: typo

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Moving this thread to the Java Forums.

      MODERATOR

      Comment

      Working...