how to connect mydatabase to java

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

how to connect mydatabase to java

Postby Magod » 18. April 2010 13:42

hi

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
Magod
 
Posts: 1
Joined: 18. April 2010 13:26

Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 9 guests