Tool Class 3

Source: Internet
Author: User
Package CN.ITCAST.JDBC;
Import java.sql.Connection;
Import Java.sql.ResultSet;
Import java.sql.SQLException;

Import java.sql.Statement;

Import Cn.itcast.jdbc.dataSource.MyDataSource2;

    Public final class Jdbcutils {private static MyDataSource2 myDataSource = null;
            Private Jdbcutils () {} static {try {Class.forName ("com.mysql.jdbc.Driver");
        myDataSource = new MyDataSource2 ();
        } catch (Exception e) {throw new Exceptionininitializererror (e); }} public static Connection getconnection () throws SQLException {//Return drivermanager.getconnection (
        URL, user, password); return Mydatasource.getconnection (); Fetch connection} public static void Free (ResultSet rs, Statement St, Connection conn) {try {if (RS
        ! = null) rs.close ();
        } catch (SQLException e) {e.printstacktrace (); } finally {try {if (ST! = NULL) st.close ();//Now the Close method is to put the connection back into the connection pool instead of closing the connection} catch (SQLException e) {
            E.printstacktrace ();
                } finally {try {if (conn! = null) conn.close ();
                } catch (Exception e) {e.printstacktrace (); }
            }
        }
    }
}

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.