Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package json.data;
- 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;
- import javax.sql.rowset.CachedRowSet;
- public class DbOperations {
- private Connection conn;
- private final String url;
- private final String dbName;
- private final String driver;
- private final String userName;
- private final String password;
- Statement stmt;
- public DbOperations() {
- conn = null;
- url = "jdbc:mysql://localhost:3306/";
- dbName = "vt";
- driver = "com.mysql.jdbc.Driver";
- userName = "root";
- password = "";
- stmt = null;
- }
- public Connection getConnection() {
- return conn;
- }
- public Statement openConnection() throws Exception {
- Class.forName(driver).newInstance();
- conn = DriverManager.getConnection(url + dbName, userName, password);
- return conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
- }
- public void closeConnection() throws Exception {
- conn.close();
- }
- public CachedRowSet createStatement() {
- Statement st1;
- CachedRowSet resWanted = null;
- try {
- st1 = conn.createStatement();
- resWanted = new com.sun.rowset.CachedRowSetImpl();
- } catch (SQLException ex) {
- Logger.getLogger(DbOperations.class.getName()).log(Level.SEVERE, null, ex);
- }
- return resWanted;
- }
- }
Add Comment
Please, Sign In to add comment