📄 dbconnection.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package IPhone;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.logging.Level;import java.util.logging.Logger;public class DBConnection { Connection conn = null; Statement stmt = null; ResultSet rs; public Connection Mobile_Master() { try { if(conn==null){ System.out.println("Loading Driver.."); Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/iphone","vikas","vikas"); } } catch (Exception e) { e.printStackTrace(); } return conn; } public void insert(String Query) { 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) { if(conn==null) conn=Mobile_Master(); insert(Query); } public ResultSet select(String Query) { 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; } public void Create(String Query) { insert(Query); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -