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

📄 dbconnection1.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 DBConnection1;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 DBConnection1 {    Connection conn = null;    Statement stmt = null;    InitialContext ctx;    DataSource ds;    ResultSet rs;    public Connection Mobile_Master(HttpSession ss) {        System.out.println("Entered to create new DBconnection");            try {                ctx = new InitialContext();                ds = (DataSource) ctx.lookup("Mobile_Brew");                try {                    conn = ds.getConnection();                    ss.setAttribute("connection", conn);                } catch (SQLException ex) {                    Logger.getLogger(DBConnection1.class.getName()).log(Level.SEVERE, null, ex);                }            } catch (NamingException ex) {                Logger.getLogger(DBConnection1.class.getName()).log(Level.SEVERE, null, ex);            }            ss.setAttribute("connection", conn);        return conn;    }    public void insert(String Query, HttpSession ss) {             if (ss.getAttribute("connection").toString().equals(""))                 Mobile_Master(ss);        try {            stmt = conn.createStatement();            stmt.execute(Query);        } catch (SQLException ex) {            Logger.getLogger(DBConnection1.class.getName()).log(Level.SEVERE, null, ex);        }            }    public void delete(String Query, HttpSession ss) {         if (ss.getAttribute("connection").toString().equals(""))                 Mobile_Master(ss);        insert(Query, ss);            }    public ResultSet select(String Query, HttpSession ss) {         if (ss.getAttribute("connection").toString().equals(""))                 Mobile_Master(ss);        try {            stmt = conn.createStatement();            stmt.execute(Query);            rs = stmt.getResultSet();        } catch (SQLException ex) {            Logger.getLogger(DBConnection1.class.getName()).log(Level.SEVERE, null, ex);        }        return rs;    }    public void Create(String Query, HttpSession ss) {        insert(Query, ss);        System.out.println("Entered in DBconnection's create session method");    }}

⌨️ 快捷键说明

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