This commit is contained in:
Lucio Lelii 2008-10-21 09:13:34 +00:00
parent 324b65bba1
commit 52bdf6380a
1 changed files with 27 additions and 29 deletions

View File

@ -8,9 +8,8 @@ import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gcube.common.core.utils.logging.GCUBELog;
import java.util.List;
import org.gcube.common.core.faults.GCUBEFault;
/**
*
@ -59,7 +58,7 @@ public class DBInterface {
*
* @param query
*/
public static synchronized void ExecuteUpdate(String query) throws RemoteException{
public static synchronized void ExecuteUpdate(String query) throws GCUBEFault{
Statement st = null;
try{
@ -67,44 +66,45 @@ public class DBInterface {
st.executeUpdate(query);
st.close();
}catch(SQLException e){//logger.error("error executing Query", e);
throw new RemoteException("error creating SQL statement",e);}
throw new GCUBEFault(e);}
}
/**
*
* @param table
* @param values
* @throws RemoteException
*/
public static synchronized void InsertInto(String table, String[][] values, boolean deleteOne) throws RemoteException {
public static synchronized void InsertInto(String table, List<List<String>> values) throws GCUBEFault {
if (values==null) return;
if (values==null) throw new GCUBEFault();
Statement st = null;
ResultSet rs = null;
try{
st = conn.createStatement(); // statement objects can be reused with
}catch(SQLException e){//logger.error("error creating SQL statement");
throw new RemoteException("error creating SQL statement",e);}
throw new GCUBEFault(e);}
String insertQuery="";
for (String[] row: values)
StringBuffer insertQuery=new StringBuffer();
for (List<String> row: values)
{
insertQuery="INSERT INTO "+table.toUpperCase()+" VALUES(";
try{
int decr=0;
if (deleteOne) decr=-1;
for (int i=0; i<row.length+decr; i++)
if (i==(row.length+decr-1)) insertQuery+="'"+row[i].replaceAll("'"," ")+"'";
else insertQuery+="'"+row[i].replaceAll("'"," ")+"',";
insertQuery+=");";
//logger.debug(insertQuery);
//System.out.println(insertQuery);
insertQuery.append("INSERT INTO ").append(table.toUpperCase()).append(" VALUES(");
st.executeUpdate(insertQuery); // run the query
try{
for(String value: row){
insertQuery.append("'").append(value.replaceAll("'", " ")).append("'");
}
insertQuery.deleteCharAt(insertQuery.length()-1).append(");");
//logger.debug(insertQuery);
st.executeUpdate(insertQuery.toString()); // run the query
}catch(SQLException e){//logger.error("HSQLDB ERROR: Problem inserting data "+e.getMessage()+" -- "+insertQuery);
}
@ -115,11 +115,7 @@ public class DBInterface {
try{
st.close();
}catch(SQLException e){//logger.error("error closing SQL statement");
throw new RemoteException("error closing SQL statement",e);}
throw new GCUBEFault(e);}
}
/**
@ -143,6 +139,8 @@ public class DBInterface {
}
/**
*
* @param table