1、你安装oracle的时候有一个文件class12.jar,那个就是oracle自己带的jdbc。
2、import那个jar就可以
3、
package DBstep;
import java.sql.*;
import java.lang.*;
import java.text.*;
import java.util.*;
public class iDBManager2000 {
public String ClassString=null;
public String ConnectionString=null;
public String UserName=null;
public String PassWord=null;
public Connection Conn;
public Statement Stmt;
public PreparedStatement prestmt=null;
public int concurType=ResultSet.CONCUR_READ_ONLY;
public int scrollType=ResultSet.TYPE_SCROLL_INSENSITIVE;
//构造函数(初始化)
public iDBManager2000() {
ClassString="oracle.jdbc.driver.OracleDriver";
ConnectionString="jdbc
racle:thin
localhost:1521
rcl";
//orcl为你的数据库的SID
UserName=...;
PassWord=...;
}
//For BBS Conn
public java.sql.Connection getBBSConn(){
try{
Class.forName(ClassString).newInstance();
if ((UserName==null) &&
(PassWord==null))
{
Conn= DriverManager.getConnection(ConnectionString);
}else
{
Conn= DriverManager.getConnection(ConnectionString,UserName,PassWord);
}
}catch(Exception e){
e.printStackTrace();
System.out.println("LICHAO");
}
return Conn ;
}
//打开数据库
public boolean OpenConnection()
{
boolean mResult=true;
try
{
Class.forName(ClassString).newInstance();
if ((UserName==null) &&
(PassWord==null))
{
Conn= DriverManager.getConnection(ConnectionString);
}
else
{
Conn= DriverManager.getConnection(ConnectionString,UserName,PassWord);
}
Stmt=Conn.createStatement(scrollType,concurType);
mResult=true;
}
catch(Exception e)
{
System.out.println(e.toString());
mResult=false;
}
return (mResult);
}
public String getStitle()
{
return stitle;
}
public String getFtitle()
{
return ftitle;
}
//关闭数据库连接
public void CloseConnection()
{
try
{
Stmt.close();
Conn.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
//取得当前时间
public String GetDateTime()
{
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mDateTime=formatter.format(cal.getTime());
return (mDateTime);
}
//执行查询语句
public ResultSet ExecuteQuery(String SqlString)
{
ResultSet result=null;
try
{
result=Stmt.executeQuery(SqlString);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return (result);
}
//执行修改语句
public int ExecuteUpdate(String SqlString)
{
int result=0;
try
{
result=Stmt.executeUpdate(SqlString);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return (result);
}
//获得当前页面的第一条记录
public int getPageResult(int pageSize,int pageNumber)
{
int result=0;
try
{
result=pageSize*(pageNumber-1);
}
catch(Exception e)
{
System.out.println(e.toString());
}
if(result==0)
{ result=1;
}
return (result);
}
//获得总页数
public int getPageCount(int pageSize,int pageCount)
{
int result=0;
try
{
if(pageCount%pageSize==0)
{
result=pageCount/pageSize;
}
else
{
result=(int)(pageCount/pageSize+1);
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
return (result);
}
//获得总记录数
public int getRecordCount(String SqlString)
{
ResultSet result=null;
int recordCount=0;
try
{
result=Stmt.executeQuery(SqlString);
if(result==null)
{
return (0);
}
else
{
result.next();
recordCount=result.getInt("count");
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
return (recordCount);
}
//封装的修改方法
public int executeUpd (String SqlString)
{
int result=0;
try
{
prestmt=Conn.prepareStatement(SqlString);
Conn.setAutoCommit(true);
result=Stmt.executeUpdate(SqlString);
Conn.commit();
}
catch(Exception e)
{
System.out.println(e.toString());
}
return (result);
}
}