Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oracle;
- import java.sql.*;
- public class Oracle {
- public static void main(String[] args) {
- Connection conn = null;
- try {
- String driverName = "oracle.jdbc.driver.OracleDriver";
- Class.forName(driverName);
- String serverName = "localhost";
- String serverPort = "1521";
- String sid = "Jami20";
- String url = "jdbc:oracle:thin:@" + serverName + ":" + serverPort + ":" + sid;
- String username = "JAMI";
- String password = "JAMI20";
- conn = DriverManager.getConnection(url, username, password);
- System.out.println("Connected to the database!");
- } catch (ClassNotFoundException e) {
- System.out.println("Could not find the database driver " + e.getMessage());
- } catch (SQLException e) {
- System.out.println("Could not connect to the database " + e.getMessage());
- }
- try {
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery("Select * from testing");
- while (rs.next()) {
- String name = rs.getString("name");
- int no = rs.getInt("no");
- System.out.println(no + ": " + name);
- }
- rs.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement