Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class ClassMid2 {
- private final String DB_URL = "jdbc:oracle:thin:@localhost:1521:orcl";
- private final String USER_ID = "scott";
- private final String PASSWORD = "tiger";
- private Connection con;
- public ClassMid2() {
- try {
- con = DriverManager.getConnection(DB_URL, USER_ID, PASSWORD);
- } catch (SQLException ex) {
- System.err.println(ex.getMessage());
- }
- }
- public void disconnectFromDB() {
- try {
- con.close();
- } catch (SQLException e) {
- System.err.println(e.getMessage());
- }
- }
- public void queryMid2() {
- String stmntStr = "SELECT * FROM Mid2";
- ResultSet rs;
- try {
- Statement stmnt = con.createStatement();
- rs = stmnt.executeQuery(stmntStr);
- while (rs.next()) {
- System.out.print(rs.getString(1));
- System.out.print("\t");
- System.out.print(rs.getString(2));
- System.out.print("\t");
- System.out.print(rs.getInt(3));
- System.out.println();
- }
- } catch (SQLException ex) {
- System.err.println(ex.getMessage());
- }
- }
- public static void main(String[] args) {
- ClassMid2 cm2 = new ClassMid2();
- cm2.queryMid2();
- cm2.disconnectFromDB();
- }
- }
Add Comment
Please, Sign In to add comment