Advertisement
Jgug

oraui.DatabaseXE

Oct 27th, 2014
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package oraui;
  2.  
  3. import oracle.jdbc.pool.OracleDataSource;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.Locale;
  10.  
  11. /**
  12.  * Created by Pavel on 26.10.14.
  13.  */
  14. public class DatabaseXE {
  15.  
  16.     private static OracleDataSource ods = null;
  17.     private static Connection con = null;
  18.  
  19.     public DatabaseXE() {
  20.     }
  21.  
  22.     public static void connect(String URL, String user, String password) throws SQLException {
  23.         ods = new OracleDataSource();
  24.         ods.setURL(URL);
  25.         ods.setUser(user);
  26.         ods.setPassword(password);
  27.         Locale.setDefault(Locale.ENGLISH);
  28.         con = ods.getConnection();
  29.         System.out.println("Connection established!");
  30.     }
  31.  
  32.     public static ResultSet executeQuery(String query) throws SQLException {
  33.         con = ods.getConnection();
  34.         Statement stm = con.createStatement();
  35.         return stm.executeQuery(query);
  36.     }
  37.  
  38.     public static boolean close() throws SQLException {
  39.         if (!ods.getConnection().isClosed()) {
  40.             ods.getConnection().close();
  41.             System.out.println("Connection closed");
  42.             return true;
  43.         } else {
  44.             System.out.println("Close failed");
  45.             return false;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement