1、;.*;lassConnOraDB{/******@Classname:ConnOraDB****@Classrole:Connecttoaoracledatabase****@Author:Dusuzhong****@Date:2010-5-4*/privatefinalStringDBDRIVER="";//驱动程序privatefinalStringDBURL="jdbc:oracle:thin:***@:1521:Test";//数据库地址privatefinalStringDBUSER="dsz779";//数据库登录用户名privatefinalStringDBPASSWORD="123456";//数据库登录密码privateConnectionconn=null;onnOraDB({/******@initialrole:完成对数据库的连接*/try{//(DBDRIVER;}catch(Exceptione{("Can'tloaddbdriver!-->"+(;}try{//连接到指定的数据库conn=(DBURL,DBUSER,DBPASSWORD;}catch(Exceptione{("Can'tconnecttothedatabase!-->"+(;}}onnectiongetConnection({/***用来使其它类调用取得数据库连接****@return数据库连接对象*/;}}2、;.*;lassExecutSingle{/******@Classname:ExecutSinle****@Classrole:ExecutesingleSQL****@Author:Dusuzhong****@Date:2010-5-4*/PrivateConnectionconn=null;PrivateStatementstmt=null;PrivateResultSetrs=null;PrivateResultSetMetaDatarsmd=null;publicExecutSingle({}PublicvoidExecuteQuery(Stringsql{/***执行单句查询,并显示结果*/IntegernumCols;StringtempValue;try{//取得数据库的连接conn=newConnOraDB(.getConnection(;stmt=(;rs=(sql;rtmt=(;numCols=(;while(({//("编号:"+("customer_id";//("/姓名:"+("customer_name";//("/性别:"+("customer_sex";//("/电话:"+("customer_phone";for(inti=1;i<=numCols;i++{tempValue=(i;if(tempValue==nulltempValue="";(tempValue;}}catch(Exceptione{(;}finally{try{if(rs!=null{(;}if(stmt!=null{(;}if(conn!=null{(;}}catch(SQLExceptione{(;}}}publicvoidExecuteSQL(Stringsql{/***执行单句操作*/try{conn=newConnOraDB(.getConnection(;stmt=(;//rs=(sql;rs=
java操作oracle的基本方式总结 来自淘豆网m.daumloan.com转载请标明出处.