Solution to problems in Java transfer process

Source: Internet
Author: User
Tags mysql tutorial

Solution to problems in Java transfer process

* Test Conn Shutdown condition
*/

Package com.hb.test;

Import java.sql.connection;

/**
*
* @author Icecold
*/
public class Testconn {
STATIC connection conn = null;

public static void Main (string[] args) throws exception {
conn = Db.getconnection ();
Db.closeconnection (conn);
Db.setconnection (conn);
if (conn = = null) {
System.out.println ("AAA");
}else {
System.out.println ("BBB");
}
}

}

Data class

*
* Database Tutorial Operation class
*/

Package com.hb.test;

Import java.sql.connection;
Import Java.sql.drivermanager;

/**
*
* @author Icecold
*/
public class DB {

public static void CloseConnection (Connection conn) {
try{
IF (conn!= null) {
Conn.close ();
conn = null;
IF (Conn. isclosed ()) {
System.out.println ("null");
}else {
System.out.println ("not null");
//                }
}
conn = null;
}catch (Exception e) {
E.printstacktrace ();
}
}
public static Connection getconnection () throws exception {
Connection conn = null;
Class.forName ("Com.mysql tutorial. Jdbc.driver");
conn = Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/test?user", "root", "123456");
Return conn;
}
public static void SetConnection (Connection conn) {
conn = null;
}
}

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.