Home > Back-end >  Myeclipse2014 connection mysql5.7
Myeclipse2014 connection mysql5.7

Time:09-26

To do homework this problem haven't solve immediately beg god to help me have a look, connect to the database failed, urgent urgent!!!
Connection code is as follows:
Package DBC.
Import the Java. SQL. Connection;
Import the Java. SQL. DriverManager;
Import the Java. SQL. SQLException;
Public class DatabaseConnection {

//define the MySQL database driver
Public static final String DBDRIVER=". Com. Mysql. JDBC Driver ".
//define the MySQL database connection address
Public static final String DBURL="JDBC: mysql://localhost: 3306/zhbit";
//MySQL database connection user name

Public static final String DBUSER="root";
//MySQL database password
Public static final String DBPASS="ax191823503";

The Connection conn=null;//database connection

Public DatabaseConnection () {
//TODO Auto - generated constructor stub
Try {
Class.forname (DBDRIVER);
} the catch (a ClassNotFoundException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}//load driver, there are abnormal

//connect the MySQL database, write user name and password, there are abnormal
Try {
Conn=DriverManager. GetConnection (DBURL, DBUSER, DBPASS);
} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}//there are abnormal
}

Public Connection getConnection () {
return conn;
}

Public void the close () {
Try {
Conn. Close ();
} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}//database closed, there are abnormal
}


Public static void main (String [] args) {
The Connection conn=null;//database connection
Try {
Class.forname (DBDRIVER);
} the catch (a ClassNotFoundException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}//load driver, there are abnormal
//connect the MySQL database, write user name and password, there are abnormal
Try {
Conn=DriverManager. GetConnection (DBURL, DBUSER, DBPASS);
} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}//there are abnormal
System. The out. Println (conn);
Try {
Conn. Close ();
} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}//database closed, there are abnormal
}

}
Error code is as follows:
The Exception in the thread "main" Java. Lang. UnsupportedClassVersionError: com/mysql/JDBC Driver: Unsupported major. The minor version 52.0
The at Java. Lang. This defineClass1 (Native Method)
The at Java. Lang. This. DefineClass (800). This Java:
The at Java. Security. SecureClassLoader. DefineClass (SecureClassLoader. Java: 142)
The at java.net.URLClassLoader.defineClass URLClassLoader. Java: (449)
The at java.net.URLClassLoader.access$100 URLClassLoader. Java: (71)
The at java.net.URLClassLoader$1.run URLClassLoader. Java: (361)
The at java.net.URLClassLoader$1.run URLClassLoader. Java: (355)
The at Java. Security. The AccessController. DoPrivileged (Native Method)
The at java.net.URLClassLoader.findClass URLClassLoader. Java: (354)
The at Java. Lang. This. LoadClass (425). This Java:
At sun. Misc. The Launcher $AppClassLoader. LoadClass (308). The Launcher Java:
The at Java. Lang. This. LoadClass (358). This Java:
The at Java. Lang. Class. ForName0 (Native Method)
The at Java. Lang. Class.forname (190) Class. Java:
The at DBC. DatabaseConnection. Main (DatabaseConnection. Java: 54)

Using the JDBC is mysql connector - Java - 5.1.39 - bin
The JDK is myeclipse's own

CodePudding user response:

The low JDK version

Use jdk1.8

CodePudding user response:

The JDK version of the problem
  • Related