06 | import oracle.jdbc.pool.OracleDataSource; |
09 | public static void main( String args[ ] ) throws SQLException { |
10 | String user = "C##userid" ; |
11 | String password = "password" ; |
12 | String database = "65.52.222.73:1521/cdb1" ; |
15 | OracleDataSource ods = new OracleDataSource( ); |
16 | ods.setURL ( "jdbc:oracle:thin:@" + database ); |
18 | ods.setPassword( password ); |
19 | Connection conn = ods.getConnection( ); |
22 | Statement stmt = conn.createStatement( ); |
24 | stmt.executeUpdate( "DELETE FROM emp_tbl" ); |
28 | String cmd = "INSERT INTO emp_tbl " ; |
29 | cmd += "SELECT empid_seq.NEXTVAL, ? FROM DUAL" ; |
30 | PreparedStatement pstmt = conn.prepareStatement( cmd ); |
33 | pstmt.setString( 1 , args[ 0 ].trim( ) ); |
37 | pstmt.setString( 1 , args[ 1 ].trim( ) ); |
42 | cmd = "INSERT INTO EMP_TBL( EMPNO, ENAME ) VALUES( ?, ? )" ; |
43 | pstmt = conn.prepareStatement( cmd ); |
45 | pstmt.setInt ( 1 , 507 ); |
46 | pstmt.setString( 2 , args[ 2 ].trim( ) ); |
52 | ResultSet rs = stmt.executeQuery( "SELECT * FROM emp_tbl" ); |
53 | while ( rs.next( ) ) { |
54 | System.out.print( "empno: " + rs.getInt( 1 ) + " " ); |
55 | System.out.print( "ename: " + rs.getString( 2 ) ); |
60 | catch ( SQLException e ) { System.out.println( e ); } |
|