Java Connection MySQL database implementation code _java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.