-2

I run WAMP and have made the MySQL database but it cannot connect. Can anyone help me?

package databasetest;
import java.sql.*;
/**
 *
 * @author kon_f
 */
public class DataBaseTest {

    private static final String USERNAME = "root";
    private static final String PASSWORD = "";
    private static final String CONN_STRING = "jdbc:mysql://localhost:3306/databasetest";

    public static void main(String[] args) throws ClassNotFoundException {
        Connection conn = null;

        try{
            conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
            System.out.println("Connected!");
        }catch (SQLException e){
            System.err.println(e);
        }

    }

}
Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
MonkeyDkon
  • 54
  • 11
  • You forgot to load the Driver. If you use Google. you will find houndreds of examples – Jens May 29 '17 at 12:45
  • run: Error: Could not find or load main class databasetest.DataBaseTest C:\Users\kon_f\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds) – MonkeyDkon May 29 '17 at 12:46
  • 1
    The second answer on this question is great for this: https://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database – Tacolibre May 29 '17 at 12:47
  • @Jens loading the driver with `Class.forName` hasn't been necessary since Java 6. – Mark Rotteveel May 29 '17 at 17:44
  • its ok now i found the way – MonkeyDkon Jul 12 '17 at 18:35

3 Answers3

0

Import the mysql jar file to the external jar directry

Manu
  • 27
  • 5
0

First You have to Load "mysqlconnector.jar" file into your Project.

and also load the driver into program

Class.forName("com.mysql.jdbc.Driver");

0

i found out what was wrong.. it was just the stupid microsoft one drive.. i deleted it and changed the directory and now its ok thanks

MonkeyDkon
  • 54
  • 11