René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Java and Oracle: Selecting from a table | ||
SelectTable.java
import java.sql.*; import oracle.jdbc.pool.OracleDataSource; class SelectTable { public static void main (String args[]) throws SQLException { OracleDataSource data_source = new OracleDataSource(); data_source.setURL ("jdbc:oracle:oci:@XE"); data_source.setUser ("rene" ); data_source.setPassword("my_secret"); Connection connection = data_source.getConnection(); PreparedStatement statement = connection.prepareStatement( "select col_1, col_2, col_3 from jdbc_test " + " where col_1 in (?, ?)" ); statement.setInt(1, 2); statement.setInt(2, 4); ResultSet result_set = statement.executeQuery(); while (result_set.next()) { System.out.println( result_set.getString(1) + "\t" + result_set.getString(2) + "\t" + result_set.getString(3) ); } } }
See also:
Creating the table and
Inserting into the table.
|