Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Clase;
- import java.sql.*;
- public class DatabaseOperations {
- public static DatabaseOperations instance = null;
- public Connection con;
- private DatabaseOperations() {
- String url = "jdbc:odbc:db1";
- String username = "root";
- String password = "root";
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- } catch(java.lang.ClassNotFoundException e) {
- System.err.print("ClassNotFoundException: ");
- System.err.println(e.getMessage());
- }
- try {
- this.con = DriverManager.getConnection(url, username, password);
- } catch(SQLException ex) {
- System.err.println("SQLException: " + ex.getMessage());
- }
- }
- public static DatabaseOperations getInstance() {
- if(instance == null) {
- instance = new DatabaseOperations();
- }
- return instance;
- }
- public ResultSet execute(String string)
- {
- DatabaseOperations db = DatabaseOperations.getInstance();
- ResultSet rs = null;
- try {
- Statement stmt = db.con.createStatement();
- rs=stmt.executeQuery(string);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.out.println(e.getMessage());
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement