码迷,mamicode.com
首页 > 其他好文 > 详细

SERVLET PRATICE

时间:2017-01-13 23:30:15      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:import   lex   line   size   ace   rman   servlet   dex   user   

 

 

1.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBConnection {
	private static final String DBDRIVER = "com.mysql.jdbc.Driver" ;			
    private static final String DBURL = "jdbc:mysql://localhost:3306/db_Struts1;
    private static final String DBUSER = "root" ;								
    private static final String DBPASSWORD = "123456";							
	public static Connection getConnection(){
		Connection conn = null;															try {
			Class.forName(DBDRIVER);											//?????
			conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);				} catch (ClassNotFoundException e) {									   e.printStackTrace();										
		} catch (SQLException e) {												
			e.printStackTrace();
		}
		return conn;
	}
	public static void close(Connection conn)  
		if(conn != null) {				 
			try {
				conn.close();			 
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void close(PreparedStatement pstmt) {
		if(pstmt != null) {				 
			try {
				pstmt.close();			 
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void close(ResultSet rs) {
		if(rs != null) {				 
			try {
				rs.close();				 
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}

SERVLET PRATICE

标签:import   lex   line   size   ace   rman   servlet   dex   user   

原文地址:http://www.cnblogs.com/anstoner/p/6284316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!