Tuesday, September 27, 2016

Debian Jessie: installing MySQL Connector/J 5.1.39 into openjdk version 1.8

Install openjdk 1.8

Edit /etc/apt/sources.list

# /etc/apt/sources.list
...
deb http://ftp.debian.org/debian jessie-backports main
...

Install openjdk 1.8

# apt-get install openjdk-8-jdk

Download and configure MySQL Connector/J

Download

# wget http://dev.mysql.com/get/Downloads/Connecctor-J/mysql-connector-java-5.1.39.tar.gz

extract

# tar -xf mysql-connector-java-5.1.39.tar.gz

Copy binary jar into openjdk 1.8

# cp mysql-connector-java-5.1.39-bin.jar /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext/

Test Connection test.java

You  don't have to run this test.java as root user. MySQL Connector/J will available to all user.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

class test {
 Connection mycon = null;

 public static void main(String[] args) {
  System.out.println("Test");
  try {
   Class.forName("com.mysql.jdbc.Driver");
   mycon = DriverManager.getConnection("jdbc:mysql://localhost/test?user=test&password=test");
  } catch (SQLException e) {
   System.out.println(e.getMessage());
  } catch (ClassNotFoundException e) {
   System.out.println(e.getMessage());
  }
 }
}

No comments:

Post a Comment