Home > Back-end >  Myeclipse link MySQL to test whether success is really very urgent very urgent thank you enough
Myeclipse link MySQL to test whether success is really very urgent very urgent thank you enough

Time:09-26

Has been the connection fails completely don't know what the reason, is going to do big homework hope to have a big help to solve the

Connection code:
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="org. GJT. Mm. Mysql. 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
}

}
Myeclipse error:

Their Internet checked the put JDBC in tomcat bin directory, but still won't do

CodePudding user response:

The mysql Driver to this: com. Mysql.. JDBC Driver

CodePudding user response:

Driver name changed to: com. Mysql.. JDBC Driver, you write is used name, basic need not now

CodePudding user response:

I don't remember JDBCjar bag put in tomcat folder, engineering can reference
  • Related