日期:2014-05-16 浏览次数:20391 次
package test.oracle;
import java.sql.*;//project 中添加ojdbc6_g.jar
public class OJ {
??? public static void main(String args[]){
??? String url = "jdbc:oracle:thin:@localhost:1521:orcl11";
??? try{
??? ??? Class.forName("oracle.jdbc.driver.OracleDriver"); //建表后先commit才能在其它端中调用
???
??? Connection conn =? DriverManager.getConnection(url,"system","bbroot");
??? Statement stmt=conn.createStatement(); //建表时的插入语句记得为' ',而不是" "
??? String strSql="SELECT * FROM Test_JC";//将sql中将;去掉
??? ResultSet rs=stmt.executeQuery(strSql);
??? while(rs.next()){
??? ??? System.out.println("TestID:"+rs.getString(1));
??? ??? System.out.println("Describe:"+rs.getString(2));
??? ??? }
??? }
??? catch(Exception e){
??? ??? e.printStackTrace();
??? }
??? System.exit(0);
}
}
输出:
TestID:001