Source Code
จะแสดง Table ใน Oracle ออกมา
--------------------------------------------------
import java.sql.* ;
//import oracle.jdbc.OracleDriver;
public class showtable{
public static void main(String[] args) throws Exception
{
System.out.println("OK");
String sql = "select * from tab" ;
getdb( sql ) ;
}
public static void getdb(String sql ) throws Exception
{
Class.forName("oracle.jdbc.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@192.168.1.2:1521:schemaname";
String user = "user" ;
String pass = "password" ;
Connection con = DriverManager.getConnection(url , user, pass) ;
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql ) ;
while(rs.next() ){
System.out.println(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
}
}
-----------------------------------------------------------------------------
run.bat
set classpath=.;c:\Program Files\Java\jdk1.6.0_13\jre\lib\ext\classes12_g.jar;
javac showtable.java
java showtable
-----------------------------------------------------------------------------
No comments:
Post a Comment