This example for you to share the Java connection MySQL database code, for your reference, the specific content as follows
Java connection MySQL database instance code package Com.abc.dao; /*dkplus specializes in collecting and compiling practical computer software tutorials, * collecting various software resources and computer peripherals, independent production of video and PPT and audio micro-public numbers, * Click into the Dkplus official blog (Java Network programming http://dkplus.iteye.com), * Micro-Letter Search Dkplus attention to the public number can get a huge amount of computer peripheral resources.
* * Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
public class Basedao {public Connection getconn () {Connection conn=null;
try {class.forname ("com.mysql.jdbc.Driver");
catch (ClassNotFoundException e) {//TODO auto-generated catch block E.printstacktrace ();
} String url= "Jdbc:mysql://127.0.0.1:3306/user";
try {conn=drivermanager.getconnection (URL, "root", "");
catch (SQLException e) {//TODO auto-generated catch block E.printstacktrace ();
Return conn;
public void CloseAll (ResultSet rs,statement stat,connection conn) {if (rs!=null) try {rs.close ();
catch (SQLException e) {//TODO auto-generated catch block E.printstacktrace (); } if (Stat!=null) try {
Stat.close ();
catch (SQLException e) {//TODO auto-generated catch block E.printstacktrace ();
} if (Conn!=null) try {conn.close ();
catch (SQLException e) {//TODO auto-generated catch block E.printstacktrace ();
}
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.