⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbconnection.java

📁 A brew application taking backup of the device
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package DBConnection;import Login.SessionUtil;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.logging.Level;import java.util.logging.Logger;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.servlet.http.HttpSession;import javax.sql.DataSource;public class DBConnection {    Connection conn = null;    Statement stmt = null;    InitialContext ctx;    DataSource ds;    ResultSet rs;    HttpSession session = SessionUtil.getSession();    public Connection Mobile_Master() throws SQLException {                   try {                if(session.getAttribute("connection").toString().equals("")) {                    System.out.println("Getting Connection..");                    ctx = new InitialContext();                    ds = (DataSource) ctx.lookup("Mobile_Master");                    conn = ds.getConnection();                    session.setAttribute("connection", conn);                } else{                    conn = (Connection) session.getAttribute("connection");                }            } catch (NamingException ex) {                Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);            }                   return conn;    }    public void insert(String Query) throws SQLException {        if (conn==null)            conn = Mobile_Master();        try {            stmt = conn.createStatement();            stmt.execute(Query);        } catch (SQLException ex) {            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);        }          }    public void delete(String Query) throws SQLException {        if (conn==null)           conn = Mobile_Master();        insert(Query);          }    public ResultSet select(String Query) throws SQLException {        if (conn==null)            conn = Mobile_Master();        try {            stmt = conn.createStatement();            stmt.execute(Query);            rs = stmt.getResultSet();        } catch (SQLException ex) {            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);        }              return rs;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -