03 | import java.sql.DatabaseMetaData; |
07 | import oracle.jdbc.pool.OracleDataSource; |
10 | public static void main( String args[ ] ) throws SQLException { |
11 | String user = "C##user_id" ; |
12 | String password = "password" ; |
13 | String database = "20.185.147.112:1521/xe" ; |
16 | OracleDataSource ods = new OracleDataSource( ); |
17 | ods.setURL ( "jdbc:oracle:thin:@" + database ); |
19 | ods.setPassword( password ); |
20 | Connection conn = ods.getConnection( ); |
23 | Statement stmt = conn.createStatement( ); |
25 | DatabaseMetaData dbm = conn.getMetaData( ); |
27 | if ( args[ 0 ].equals( "drop" ) ) { |
28 | cmd = "drop table student_table" ; |
29 | System.out.println( cmd ); |
33 | else if ( args[ 0 ].equals( "create" ) ) { |
36 | null , "C##user_id" , "STUDENT_TABLE" , new String[] { "TABLE" } ); |
39 | cmd = "drop table student_table" ; |
40 | System.out.println( cmd ); |
44 | cmd = "create table student_table (" ; |
45 | cmd += " ID integer generated always as identity," ; |
46 | cmd += " name VARCHAR(32)," ; |
47 | cmd += " age INTEGER )" ; |
48 | System.out.println( cmd ); |
51 | cmd = "insert into student_table( name, age ) values (" ; |
52 | cmd += " 'Digi Mon', 10 )" ; |
53 | System.out.println( cmd ); |
58 | else if ( args[ 0 ].equals( "insert" ) ) { |
59 | cmd = "insert into student_table( name, age ) values ( '" ; |
60 | cmd += args[ 1 ].trim( ) + "', '" + args[ 2 ].trim( ) + "' )" ; |
61 | System.out.println( cmd ); |
65 | else if ( args[ 0 ].equals( "select" ) ) { |
66 | cmd = "select * from student_table s where " ; |
67 | cmd += "name like '%" + args[ 1 ].trim( ) + "%'" ; |
68 | System.out.println( cmd ); |
69 | rset = stmt.executeQuery( cmd ); |
71 | while ( rset.next( ) ) { |
73 | System.out.println( "\nStudent ID => " + rset.getInt( 1 ) ); |
74 | System.out.println( "Student name => " + rset.getString( 2 ) ); |
75 | System.out.println( "Student age => " + rset.getInt( 3 ) ); |
|