package test;
import java.sql.*;
public class SevenJdbc {
static final String url = "jdbc:oracle:thin:@192.168.3.211:1521:chi";
static final String userID = "scott";
static final String passwd = "oracle";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public static void main(String[] args) {
new SevenJdbc().TestCallable();
}
public void TestCallable(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, userID, passwd);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from test1");
ResultSetMetaData rsm = rs.getMetaData();
System.out.println(rsm.getColumnCount());
System.out.println(rsm.getColumnLabel(1));
System.out.println(rsm.getColumnName(2));
}catch(Exception e){
e.printStackTrace();
}
finally{
if(conn!= null){
try{conn.close();}catch(Exception ex){ex.printStackTrace();}
}
}
}
}
import java.sql.*;
public class SevenJdbc {
static final String url = "jdbc:oracle:thin:@192.168.3.211:1521:chi";
static final String userID = "scott";
static final String passwd = "oracle";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public static void main(String[] args) {
new SevenJdbc().TestCallable();
}
public void TestCallable(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, userID, passwd);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from test1");
ResultSetMetaData rsm = rs.getMetaData();
System.out.println(rsm.getColumnCount());
System.out.println(rsm.getColumnLabel(1));
System.out.println(rsm.getColumnName(2));
}catch(Exception e){
e.printStackTrace();
}
finally{
if(conn!= null){
try{conn.close();}catch(Exception ex){ex.printStackTrace();}
}
}
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27042095/viewspace-1190542/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27042095/viewspace-1190542/