Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- String host = "172.23.9.185";
- String port = "1521";
- String sid = "orcl";
- String user = "MHS175314019";
- String password = "MHS175314019";
- Connection conn = null;
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- conn = DriverManager.getConnection("jdbc:oracle:thin:@" + host + ":" + port + ":" + sid, user, password);
- String query = "select employee_id, first_name, last_name, email from employees";
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery(query);
- while (rs.next()) {
- System.out.println(rs.getInt("employee_id") + "|" + rs.getString("first_name")
- + " " + rs.getString("last_name") + "|" + rs.getString("email"));
- }
- rs.close();
- st.close();
- } catch (ClassNotFoundException ex) {
- System.out.println(ex.toString());
- } catch (SQLException ex) {
- System.out.println(ex.toString());
- } finally {
- try {
- conn.close();
- } catch (SQLException ex) {
- System.out.println(ex.toString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement