Has been reported Org.apache.commons.dbcp.poolingdatasource$poolguardconnectionwrapper cannot is cast to Oracle.jdbc.OracleConnection later according to the session to get the connnection and then go to get a con = Con.getmetadata (). getconnection ();
The following is the complete code:
------Here is to create a stored procedure
Create or replace type Enroll as Object (
Name VARCHAR2 (50),
Idcard varchar2 (20),
Sex number (1),
Age Number (8),
Place Varchar2 (50),
Enrolltime date,
Enrollresult varchar2 (20),
Enrollfailinfo varchar2 (100),
Enrollcanal VARCHAR2 (100)
);
CREATE OR REPLACE TYPE enrollinfolist as Table of enroll;
--Create sequence
Create sequence enrollinfo_id
MinValue 1
MaxValue 99999999
Start with 1
Increment by 1;
--Process
Create or replace procedure Pullenrollinfo (
Enrollinfo in Enrollinfolist
)
Is
V_sql VARCHAR2 (200);
Num number:=0;
Begin
For I in 1..enrollinfo.count loop
V_sql:= ' SELECT COUNT (*) from enrollinfo where idcard= ' | | Enrollinfo (i). Idcard;
Execute immediate v_sql into Num;
If Num>0 Then
Update Enrollinfo set Name=enrollinfo (i). Name, Sex=enrollinfo (i). Sex, Age=enrollinfo (i). Age, Place=enrollinfo (i). Place, Enrolltime=enrollinfo (i). Enrolltime, Enrollresult=enrollinfo (i). Enrollresult, Enrollfailinfo=enrollinfo (i) . Enrollfailinfo, Enrollcanal=enrollinfo (i). enrollcanal where Idcard=enrollinfo (i). Idcard;
Else
Insert into Enrollinfo (Id,name,idcard,sex,age,place, enrolltime,enrollresult,enrollfailinfo,enrollcanal) VALUES ( Enrollinfo_id.nextval,enrollinfo (i). Name,enrollinfo (i). Idcard,enrollinfo (i). Sex
, Enrollinfo (i). Age,enrollinfo (i). Place,enrollinfo (i). Enrolltime,enrollinfo (i). Enrollresult,enrollinfo (i). Enrollfailinfo,enrollinfo (i). enrollcanal);
End If;
If mod (i,500) =0 Then
Commit
End If;
End Loop;
Commit
End Pullenrollinfo;
----Java code
public void Insertclientdata (list<enrollinfo> infos) {
Connection con = null;
CallableStatement stmt = null;
try {
con = Sessionfactoryutils.getdatasource (
This.gethibernatetemplate (). Getsessionfactory ())
. getconnection ();
con = Con.getmetadata (). getconnection ();
list<struct> structs = new arraylist<struct> ();
Array array = GetArray (Con, "ENROLL", "Enrollinfolist", infos);
stmt = Con.preparecall ("{Call Pullenrollinfo (?)}");
Stmt.setarray (1, array);
Stmt.execute ();
} catch (Exception e) {
TODO auto-generated Catch block
Log.error ("Error fetching Customer Information:" + e);
} finally {
if (stmt! = null) {
try {
Stmt.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
}
if (con! = null) {
try {
Con.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
}
}
}
Public ARRAY GetArray (Connection con, string oraobjtype, String Oraarrtype,
List<enrollinfo> infos) throws Exception {
ARRAY list = null;
if (infos! = null && infos.size () > 0) {
Oracle-recognized collection object that matches a collection of Java objects
Struct[] structs = new struct[infos.size ()];
Oracle-recognized object templates that match a single Java object
Structdescriptor Structdesc = new Structdescriptor (Oraobjtype, con);
Traverse Stulist to convert each student object to an Oracle-recognizable template object
for (int i = 0; i < infos.size (); i++) {
Java objects
Enrollinfo info= Infos.get (i);
The size of the array should be the number of properties of the database object (STUDENT) you defined
object[] TObject = new OBJECT[9];
Tobject[0] = Info.getname ();
TOBJECT[1] = Info.getidcard ();
TOBJECT[2] = Info.getsex ();
TOBJECT[3] = Info.getage ();
TOBJECT[4] = Info.getplace ();
TOBJECT[5] = new Date (123);
TOBJECT[6] = Info.getenrollresult ();
TOBJECT[7] = Info.getenrollfailinfo ();
TOBJECT[8] = info.getenrollcanal ();
Structs[i] = new STRUCT (Structdesc, con, tobject);
}
Match list
Arraydescriptor desc = arraydescriptor.createdescriptor (Oraarrtype,
Con);
List = new ARRAY (desc, con, structs);
}
return list;
}
Storage structure receive array