这是a.h
/********************************************************
* class name:COCIInterface
* purpose:ORACLE数据库接口类(不支持事务镶嵌,使用本地事务)
* Language:C++
* version: 1.0
* OS Platform:
* Author:huangjb
* Date: 2001.11.4
* Cpryight (C) Nanjing Linkage System Integration CO.,LTD.
********************************************************//***************Modify History******************************
* person date modify context res
*
*
*********************************************************/
#if !defined( __C_OCIInterface_H__LOCAL_TRANSACTION)
#define define __C_OCIInterface_H__LOCAL_TRANSACTION#include <string.h>
#include <stdio.h>
#include "oci.h"
#include "DBInterface.h"
class COCIInterface:public CDatabaseInterface
{
public:
/*获取本接口类的版本信息*/
char* fnGetVer ();
/*连接数据库*/
int fnConnect (char * strUid, char * strPwd,char * strServer) ;
/*开始事务*/
int fnBeginTran (int iTransNo=0 );
/*执行sql语句*/
int fnExecsql (char * strSql,SData *SData_out=NULL, int iTransNo = 0,int iRowNums = 1,int * iExecRows=NULL);
/*向下移动游标*/
int fnMoveNext (int iTransNo=0, int iRowNums=1,int * iExecRows=NULL);
/*执行存储过程三个函数:设置存储过程名字,创建存储过程参数,执行存储过程,
在这里没有实现, 是为了统一与SYBASE接口类的接口*/
int fnSetRPCName(char* strRPC){return 1;};
int fnCreateRPCPara(const char* strParaName,int para_type,int direction,int size=-99999,void* value=NULL){return 1;};
int fnExecRPC(SData * SData_out=NULL){return 1;};
/*提交事务*/
int fnCommit (int iTransNo=0);
/*回滚事务*/
int fnRollback (int iTransNo=0);
/*关闭数据库连接*/
int fnClose ();
/*错误报告*/
char* fnReportError(char *msg=NULL);
public:
/*构造函数*/
COCIInterface();
/*析构函数*/
~COCIInterface();
private: OCIEnv *m_envhp;
OCIServer *m_srvhp;
OCIError *m_errhp;
OCISvcCtx *m_svchp;
OCIStmt *m_stmthp;
OCISession *m_authp;
private:
/*释放所有已分配句柄*/
int fnFreeHandles();
};#endif //!defined( __C_OCIInterface_H__LOCAL_TRANSACTION)
/********************************************************
* class name:COCIInterface
* purpose:ORACLE数据库接口类(不支持事务镶嵌,使用本地事务)
* Language:C++
* version: 1.0
* OS Platform:
* Author:huangjb
* Date: 2001.11.4
* Cpryight (C) Nanjing Linkage System Integration CO.,LTD.
********************************************************//***************Modify History******************************
* person date modify context res
*
*
*********************************************************/
#if !defined( __C_OCIInterface_H__LOCAL_TRANSACTION)
#define define __C_OCIInterface_H__LOCAL_TRANSACTION#include <string.h>
#include <stdio.h>
#include "oci.h"
#include "DBInterface.h"
class COCIInterface:public CDatabaseInterface
{
public:
/*获取本接口类的版本信息*/
char* fnGetVer ();
/*连接数据库*/
int fnConnect (char * strUid, char * strPwd,char * strServer) ;
/*开始事务*/
int fnBeginTran (int iTransNo=0 );
/*执行sql语句*/
int fnExecsql (char * strSql,SData *SData_out=NULL, int iTransNo = 0,int iRowNums = 1,int * iExecRows=NULL);
/*向下移动游标*/
int fnMoveNext (int iTransNo=0, int iRowNums=1,int * iExecRows=NULL);
/*执行存储过程三个函数:设置存储过程名字,创建存储过程参数,执行存储过程,
在这里没有实现, 是为了统一与SYBASE接口类的接口*/
int fnSetRPCName(char* strRPC){return 1;};
int fnCreateRPCPara(const char* strParaName,int para_type,int direction,int size=-99999,void* value=NULL){return 1;};
int fnExecRPC(SData * SData_out=NULL){return 1;};
/*提交事务*/
int fnCommit (int iTransNo=0);
/*回滚事务*/
int fnRollback (int iTransNo=0);
/*关闭数据库连接*/
int fnClose ();
/*错误报告*/
char* fnReportError(char *msg=NULL);
public:
/*构造函数*/
COCIInterface();
/*析构函数*/
~COCIInterface();
private: OCIEnv *m_envhp;
OCIServer *m_srvhp;
OCIError *m_errhp;
OCISvcCtx *m_svchp;
OCIStmt *m_stmthp;
OCISession *m_authp;
private:
/*释放所有已分配句柄*/
int fnFreeHandles();
};#endif //!defined( __C_OCIInterface_H__LOCAL_TRANSACTION)
{
public static void main (String args []) throws SQLException{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "username", "password");
//关闭自动提交,提高效率
conn.setAutoCommit(false); // 用PreparedStatement可提高效率
PreparedStatement stmt = conn.createStatement (); // Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select sno,sname from student"); // Iterate through the result and print the employee names
while (rset.next ()){
System.out.println (rset.getString (1));
System.out.println (rset.getString (2));
}
// Close the RseultSet
rset.close(); // Close the Statement
stmt.close(); // Close the connection
conn.close();
}
}