Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbconnect;
- import java.sql.*;
- import oracle.jdbc.*;
- import oracle.jdbc.pool.OracleDataSource;
- /**
- *
- * @author Assunta
- */
- public class DBConnect {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws SQLException {
- Connection conn = null;
- try {
- // Connessione con DataSource
- OracleDataSource ods = new OracleDataSource();
- ods.setURL("jdbc:oracle:thin:@localhost:1521/xe");
- ods.setUser("SYSTEM");
- ods.setPassword("ciaociao");
- System.out.println("Trying to connect to the database...");
- conn = ods.getConnection();
- System.out.println("Connection Established...");
- //Query
- Statement stmt = conn.createStatement();
- ResultSet rset = stmt.executeQuery("SELECT PEDINA FROM GIOCA_PARTITA");
- //Outp
- while(rset.next()) System.out.println(rset.getString(1));
- } catch (SQLException e) {
- System.out.println("Errore: " + e.getMessage());
- // could not connect to the database
- } finally {
- if(conn != null) conn.close();
- }
- }
- }
Add Comment
Please, Sign In to add comment