Here is the code that i am using to connect to MysSQL
database using java.....
I am getting a runtime error...
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Java2MySql
{
public static void main(String[] args)
{
String url = "jdbc:mysql://localhost:3306/";
String dbName = "java_test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "plsdonthack";
try
{
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I am running it like this :
java -cp "$HOME/OOPS-Files/Code/learn/Driver/mysql-connector-java-5.1.34-bin.jar" Java2MySql
I have the .jar
file there.
Here is the Error Message That i get when i run it.
I have physically gone and checked the folder com/mysql/jdbc and have found the file called Driver.java there....
Error: Could not find or load main class Java2MySql