Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oraui;
- import oracle.jdbc.pool.OracleDataSource;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Locale;
- /**
- * Created by Pavel on 26.10.14.
- */
- public class DatabaseXE {
- private static OracleDataSource ods = null;
- private static Connection con = null;
- public DatabaseXE() {
- }
- public static void connect(String URL, String user, String password) throws SQLException {
- ods = new OracleDataSource();
- ods.setURL(URL);
- ods.setUser(user);
- ods.setPassword(password);
- Locale.setDefault(Locale.ENGLISH);
- con = ods.getConnection();
- System.out.println("Connection established!");
- }
- public static ResultSet executeQuery(String query) throws SQLException {
- con = ods.getConnection();
- Statement stm = con.createStatement();
- return stm.executeQuery(query);
- }
- public static boolean close() throws SQLException {
- if (!ods.getConnection().isClosed()) {
- ods.getConnection().close();
- System.out.println("Connection closed");
- return true;
- } else {
- System.out.println("Close failed");
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement