Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.189:1521:"+HString,User,Pwd);
if(bVal.compareTo("true")==0)
{
int IdIndex = 0;
int IdIndex2 = 0;
int LastIndex = 1;
/**
* Get the last id_event from the latestevents table
*/
String stmtString = new String("select id_event from latestevents");
/**
* start getting the data from the table
*/
stmt = con.createStatement();
rs = stmt.executeQuery(stmtString);
while(rs.next())
{
LastIndex++;
}
out.println(LastIndex);
File jclastevent = new File("E:\\oracle\\ora92\\Apache\\Jserv\\servlets/"+Xmlpath); // latestevents.xml
FileInputStream istreamxml = new FileInputStream(jclastevent);
File eventimg1 = new File("E:\\oracle\\ora92\\Apache\\Jserv\\servlets/"+IPath);
FileInputStream istreamImage1 = new FileInputStream(eventimg1);
for(int j=1;j<=LastIndex;j++)
{
try
{
IdIndex = LastIndex*j - 10*(j-1)-(LastIndex-9)*(j-1);
PreparedStatement ps = con.prepareStatement("update latestevents set id_event=? where id_event="+IdIndex);
try
{
out.println("IdIndex: "+(IdIndex+1));
ps.setInt(1,IdIndex+1);
ps.executeUpdate();
}catch(Exception exc){out.println(exc.getMessage());}
finally{ps.close();}
out.println("Step1");
}catch(Exception exc){out.println(exc.getMessage());}
}
PreparedStatement pStmt = con.prepareStatement("insert into latestevents(id_event, eventdate,xmlfile, image)" +
"values(?,To_Date(?, 'DD-MM-YYYY'), ?, ?)");
try
{
pStmt.setInt(1,1);
pStmt.setString(2,ODate);
pStmt.setBinaryStream(3,istreamxml, (int) jclastevent.length());
pStmt.setBinaryStream(4,istreamImage1, (int) eventimg1.length());
pStmt.executeUpdate();
}
catch(Exception exc)
{
out.println(exc.getMessage());
checkconnection = exc.getMessage();
}
finally{pStmt.close();
istreamxml.close();
istreamImage1.close();}
}
}
catch(ClassNotFoundException e)
{
checkconnection = "Could not load database driver:"
+e.getMessage();
out.println("Could not load database driver:"
+e.getMessage());
}
catch(SQLException e)
{
checkconnection = "SQLException: "+e.getMessage();
}
finally
{
/**
* close connection no matter what
**/
try
{
if(con!=null)
{
con.close();
}
}catch(SQLException ignored){}
}
Partager