Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exercises;
- import java.sql.*;
- public class JDBCex2 {
- static Connection conn = null;
- static Statement stmt = null;
- static String dbURL = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
- static String user = "labs";
- static String password = "labs";
- public JDBCex2() { }
- public static void main (String args[]) throws SQLException {
- try {
- conn = DriverManager.getConnection(dbURL, user, password);
- conn.clearWarnings();
- System.out.println("Connection opened! For driver ==>Oracle 11XE");
- stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select * from customers");
- while (rs.next()) {
- System.out.println(rs.getString(2) + " " + rs.getString("CUSTLASTNAME"));
- }
- rs.close();
- } catch (SQLException e) {
- System.err.println(e.getMessage());
- } finally {
- if (!conn.isClosed()) {
- conn.close();
- System.out.println("Connection closed! Oracle");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement