ineed to know how to connect mydatabase to java.
i have searshed for any way to do this thing and i find this code
- Code: Select all
import java.sql.*;
public class main{
public static void main(String[] args)
{
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
// Create a connection to the database
String serverName = "localhost";
String mydatabase = "study";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "root";
String password = "";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage() + " :1");// Could not find the database driver
} catch (SQLException e) {
System.out.println(e.getMessage()+ " :2");// Could not connect to the database
}
}
}
result: org.gjt.mm.mysql.Driver :1