Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class TestConnection {
- public static void main(String args[]) {
- String url = "jdbc:oracle:thin:@localhost:1521:orcl";
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- System.out.println("Driver Loaded");
- Connection con = DriverManager.getConnection(url, "cricbuzz", "cse216");
- System.out.println("Connection established");
- //Do all work related to this connection;
- Statement statement = con.createStatement();
- ResultSet rs = statement.executeQuery("select * from out_type");
- while(rs.next()) {
- System.out.println(rs.getInt("out_id"));
- System.out.println(rs.getString("out_title"));
- }
- con.close();
- }
- catch (ClassNotFoundException e) {
- System.out.println("Driver not loaded");
- }
- catch (SQLException e) {
- System.out.println("Connection not established");
- }
- }
- }
Add Comment
Please, Sign In to add comment