首页 > 代码库 > SERVLET PRATICE
SERVLET PRATICE
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。