Guest User

Untitled

a guest
Sep 27th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package dbconnect;
  2. import java.sql.*;
  3. import oracle.jdbc.*;
  4. import oracle.jdbc.pool.OracleDataSource;
  5.  
  6. /**
  7.  *
  8.  * @author Assunta
  9.  */
  10. public class DBConnect {
  11.  
  12.     /**
  13.      * @param args the command line arguments
  14.      */
  15.     public static void main(String[] args) throws SQLException {
  16.         Connection conn = null;
  17.        
  18.         try {
  19.             // Connessione con DataSource
  20.             OracleDataSource ods = new OracleDataSource();
  21.             ods.setURL("jdbc:oracle:thin:@localhost:1521/xe");
  22.             ods.setUser("SYSTEM");
  23.             ods.setPassword("ciaociao");
  24.             System.out.println("Trying to connect to the database...");
  25.             conn = ods.getConnection();
  26.             System.out.println("Connection Established...");
  27.             //Query
  28.             Statement stmt = conn.createStatement();
  29.             ResultSet rset = stmt.executeQuery("SELECT PEDINA FROM GIOCA_PARTITA");
  30.            
  31.             //Outp
  32.             while(rset.next()) System.out.println(rset.getString(1));
  33.            
  34.         } catch (SQLException e) {
  35.             System.out.println("Errore: " + e.getMessage());
  36.             // could not connect to the database
  37.         } finally {
  38.             if(conn != null) conn.close();
  39.         }
  40.         }
  41.     }
Add Comment
Please, Sign In to add comment