git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vre-management/VREModeler@5147 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
324b65bba1
commit
52bdf6380a
|
@ -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="";
|
||||
StringBuffer insertQuery=new StringBuffer();
|
||||
|
||||
for (String[] row: values)
|
||||
for (List<String> row: values)
|
||||
{
|
||||
insertQuery="INSERT INTO "+table.toUpperCase()+" VALUES(";
|
||||
insertQuery.append("INSERT INTO ").append(table.toUpperCase()).append(" 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("'"," ")+"',";
|
||||
for(String value: row){
|
||||
insertQuery.append("'").append(value.replaceAll("'", " ")).append("'");
|
||||
}
|
||||
|
||||
insertQuery+=");";
|
||||
insertQuery.deleteCharAt(insertQuery.length()-1).append(");");
|
||||
//logger.debug(insertQuery);
|
||||
//System.out.println(insertQuery);
|
||||
|
||||
st.executeUpdate(insertQuery); // run the query
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue