日期:2014-05-19 浏览次数:20682 次
package com.hsp.controller;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class index {
Connection ct=null;
Statement sm=null;
ResultSet rs=null;
public ResultSet excuteQuery(String sql){
try {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
String user = "scott";
String psw = "tiger";
//得到连接
Connection ct = DriverManager.getConnection(url,user,psw);
//创建Statement
Statement sm;
sm = ct.createStatement();
rs = sm.executeQuery(sql);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//删除与插入不能使用executeQuery
return rs;
}//excuteQuery
public static void main(String[] args){
index index=new index();
ResultSet rr=index.excuteQuery("select * from web_content");
try {
if(rr.next()){System.out.print(rr.getString(4));}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//main
}//index