|
From: Irina Z. <i_z...@us...> - 2004-03-31 21:24:46
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5624/src/org/cobricks/core/db Modified Files: DBAccessImpl.java Log Message: Processing of Set of values for sqlQuery(String, List, int) Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- DBAccessImpl.java 23 Feb 2004 08:20:59 -0000 1.6 +++ DBAccessImpl.java 31 Mar 2004 21:12:55 -0000 1.7 @@ -433,10 +433,10 @@ } protected void setPreparedObjects(PreparedStatement pstmt, - List objects) + Set objects) throws SQLException { - ListIterator i = objects.listIterator(); + Iterator i = objects.iterator(); int count = 1; while (i.hasNext()) { Object o = i.next(); @@ -479,7 +479,7 @@ pstmt.setString(position, ""); } else { - pstmt.setString(position, o.toString()); + pstmt.setString(position, o.toString().trim()); } } return 1; @@ -833,7 +833,15 @@ int pcount = 1; ListIterator i = objects.listIterator(); while (i.hasNext()) { - setPreparedObject(pstmt, i.next(), pcount++); + Object next = i.next(); + if (next instanceof Set) { + Set nextList = (Set) next; + setPreparedObjects(pstmt, nextList); + + } + else{ + setPreparedObject(pstmt, next, pcount++); + } } ResultSet rs = pstmt.executeQuery(); while (rs.next()) { |
|
From: Michael K. <ko...@us...> - 2004-08-11 15:11:54
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12938/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- DBAccessImpl.java 16 Jul 2004 08:18:56 -0000 1.10 +++ DBAccessImpl.java 11 Aug 2004 15:11:44 -0000 1.11 @@ -43,9 +43,9 @@ static Logger logger = Logger.getLogger(DBAccessImpl.class); - final static int DBTYPE_SQL92 = 0; - final static int DBTYPE_MYSQL = 1; - final static int DBTYPE_POSTGRES = 2; + final public static int DBTYPE_SQL92 = 0; + final public static int DBTYPE_MYSQL = 1; + final public static int DBTYPE_POSTGRES = 2; int dbtype = DBTYPE_SQL92; CoreManager coreManager; |
|
From: Michael K. <ko...@us...> - 2004-12-07 16:16:23
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2681/core/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- DBAccessImpl.java 25 Oct 2004 06:46:33 -0000 1.12 +++ DBAccessImpl.java 7 Dec 2004 16:15:27 -0000 1.13 @@ -16,11 +16,10 @@ import java.util.*; import java.sql.*; - import org.apache.commons.dbcp.*; import org.apache.commons.pool.ObjectPool; import org.apache.commons.pool.impl.GenericObjectPool; -import org.apache.log4j.*; +import org.apache.log4j.Logger; import org.cobricks.core.CobricksException; import org.cobricks.core.CoreManager; @@ -28,7 +27,6 @@ import org.cobricks.core.util.ResourceUtil; - /** * Implementation of the database abstraction interface DBAccess * for the database systems MySQL and PostgreSQL (and similar |
|
From: Michael K. <ko...@us...> - 2005-01-19 15:25:05
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28189/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- DBAccessImpl.java 7 Dec 2004 16:15:27 -0000 1.13 +++ DBAccessImpl.java 19 Jan 2005 15:24:52 -0000 1.14 @@ -831,6 +831,11 @@ */ public List sqlQuery(String sql, int maxRows) { + // tbd: we might want to use the QueryRunner class in the + // Apache Jakarta JDBC Utility Component instead: + // QueryRunner run = new QueryRunner(dataSource); + // Object[] result = (Object[])run.query(...); + logger.debug("sqlQuery("+sql+")"); List result = new ArrayList(); Connection conn = null; |
|
From: Michael K. <ko...@us...> - 2005-02-08 16:20:41
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15015/org/cobricks/core/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- DBAccessImpl.java 19 Jan 2005 15:24:52 -0000 1.14 +++ DBAccessImpl.java 8 Feb 2005 16:20:01 -0000 1.15 @@ -1097,6 +1097,7 @@ */ public boolean createTable(String tablename) { + logger.info("Creating table "+tablename); DBTableDescriptor td = (DBTableDescriptor) tableDescriptors.get(tablename); if (td == null) { |
|
From: Thorsten E. <fre...@us...> - 2005-02-18 20:45:11
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27226/src/org/cobricks/core/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- DBAccessImpl.java 8 Feb 2005 16:20:01 -0000 1.15 +++ DBAccessImpl.java 18 Feb 2005 20:44:44 -0000 1.16 @@ -943,6 +943,43 @@ } return result; } + + + /** + * Return the results of the given query - as a list of maps, each map + * holds the attributnames and the attributes returned by the query. + * The attributnames are uniquely specified in terms of sql table storage + * position. + * Only used in {@link org.cobricks.item.ItemSearch# + * createAndExecuteSQL(SQLStructure, DBAccess) createAndExecuteSQL()}. + */ + public List sqlQuerySpecificIdent(String sql) + { + logger.debug("sqlQuery("+sql+")"); + List result = new ArrayList(); + Connection conn = null; + Statement stmt = null; + try { + conn = dataSource.getConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()) { + Map result2 = new HashMap(); + getSingleRowAttributes(result2, rs); + result.add(result2); + } + rs.close(); + } catch(Exception e) { + e.printStackTrace(); + logger.error(LogUtil.exception("Failed executing sql statement: " + +sql, e)); + } finally { + try { stmt.close(); } catch (Exception e) { } + try { conn.close(); } catch (Exception e) { } + } + logger.debug("sqlQuery returned "+result.size()+" results"); + return result; + } /** @@ -1011,7 +1048,83 @@ } } } - + + + /** + * Auxiliary method and only used for/in + * {#sqlQuerySpecificIdent(String) sqlQuerySpecificIdent(String)}. + * + * Read the attributes of one row from the result set of a query. + * The attributes are more closely specified by the storage location in the + * rel. database using the pattern: + * 'specified_name' ::= 'db_tablename' '.' 'db_attributename' + */ + public void getSingleRowAttrsSpec(Map result, ResultSet rs) + throws SQLException + { + ResultSetMetaData rsmd = rs.getMetaData(); + int numCols = rsmd.getColumnCount(); + for (int i=1; i<=numCols; i++) { + String tableLabel = rsmd.getColumnLabel(i); + int pos = tableLabel.indexOf("."); + if (pos>-1) tableLabel = tableLabel.substring(pos+1); + String tableName = rsmd.getTableName(i); + String label = tableName + "." + tableLabel; + int coltype = rsmd.getColumnType(i); + if (coltype == java.sql.Types.CLOB) { + String tmps = rs.getString(i); + if (tmps == null) tmps = ""; + if (tmps.startsWith("[[")) { + result.put(label.toLowerCase(), stringToSet(tmps)); + } else { + result.put(label.toLowerCase(), tmps); + } + continue; + } + if (coltype == java.sql.Types.BINARY) { + byte[] bytes = rs.getBytes(i); + if (bytes!=null) result.put(label.toLowerCase(), bytes); + continue; + } + if (coltype == java.sql.Types.LONGVARBINARY) { + byte[] bytes = rs.getBytes(i); + if (bytes!=null) result.put(label.toLowerCase(), bytes); + continue; + } + if (coltype == java.sql.Types.TIMESTAMP) { + Timestamp ts = rs.getTimestamp(i); + if (ts != null) + result.put(label.toLowerCase(), ts); + continue; + } + if (coltype == java.sql.Types.DATE) { + java.util.Date d = rs.getDate(i); + if (d != null) + result.put(label.toLowerCase(), d); + continue; + } + if (coltype == java.sql.Types.INTEGER) { + Integer d = new Integer(rs.getInt(i)); + if (d != null) + result.put(label.toLowerCase(), d); + continue; + } + + Object o = ""; + try { + o = rs.getString(i); + } catch(Exception e) { } + if (rs.wasNull()) o = null; + if (o != null) { + if (((String)o).startsWith("[[")) { + result.put(label.toLowerCase(), stringToSet((String)o)); + } else { + result.put(label.toLowerCase(), o); + } + } + } + } + /** * Execute the given SQL statement. |
|
From: Michael K. <ko...@us...> - 2005-05-26 14:03:37
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23917/org/cobricks/core/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- DBAccessImpl.java 18 Feb 2005 20:44:44 -0000 1.16 +++ DBAccessImpl.java 26 May 2005 14:02:38 -0000 1.17 @@ -1016,10 +1016,20 @@ continue; } if (coltype == java.sql.Types.TIMESTAMP) { - Timestamp ts = rs.getTimestamp(i); - if (ts != null) - result.put(label.toLowerCase(), ts); - continue; + try { + Timestamp ts = rs.getTimestamp(i); + if (ts != null) + result.put(label.toLowerCase(), ts); + continue; + } catch (Exception e) { + Object o = rs.getObject(i); + if (o != null) { + logger.warn("Failed reading timestamp value from: " + +o.toString()+" "+o.getClass().getName()); + } else { + logger.warn("Failed reading timestamp value from NULL"); + } + } } if (coltype == java.sql.Types.DATE) { java.util.Date d = rs.getDate(i); |
|
From: Michael K. <ko...@us...> - 2005-08-10 13:31:42
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5106/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- DBAccessImpl.java 26 May 2005 14:02:38 -0000 1.17 +++ DBAccessImpl.java 10 Aug 2005 13:31:33 -0000 1.18 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2004 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2005 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -326,6 +326,7 @@ if (primarykeyAttr != null) { primarykeyValue = getNewPrimaryKey(tablename, primarykeyAttr); result = Integer.parseInt(primarykeyValue); + attrnames.remove(primarykeyAttr); } StringBuffer sb = new StringBuffer("insert into "); sb.append(tablename); @@ -337,7 +338,8 @@ ListIterator i = attrnames.listIterator(); while (i.hasNext()) { - sb.append((String)i.next()); + String aname = (String)i.next(); + sb.append(aname); if (i.hasNext()) sb.append(", "); } sb.append(") values ("); @@ -351,8 +353,7 @@ // Instead of values inside of values SQL clause we insert placeholders // here. The concrete values will be set by corresponding JDBC calls. while (i.hasNext()) { - sb.append("?"); - i.next(); + sb.append("?"); i.next(); if (i.hasNext()) sb.append(", "); } sb.append(")"); @@ -965,7 +966,7 @@ ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { Map result2 = new HashMap(); - getSingleRowAttributes(result2, rs); + getSingleRowItemids(result2, rs); result.add(result2); } rs.close(); @@ -1061,6 +1062,35 @@ /** + * Read and store the itemids of one row + * from the result set of a query. + */ + public void getSingleRowItemids(Map result, ResultSet rs) + throws SQLException + { + ResultSetMetaData rsmd = rs.getMetaData(); + int numCols = rsmd.getColumnCount(); + List idList = new ArrayList(); + String label = null; + for (int i=1; i<=numCols; i++) { + label = rsmd.getColumnLabel(i); + int pos = label.indexOf("."); + if (pos>-1) label = label.substring(pos+1); + label.toLowerCase(); + int coltype = rsmd.getColumnType(i); + if (coltype == java.sql.Types.INTEGER) { + Integer d = new Integer(rs.getInt(i)); + if (d != null) { + idList.add(d); + } + continue; + } + } + result.put(label, idList); + } + + + /** * Auxiliary method and only used for/in * {#sqlQuerySpecificIdent(String) sqlQuerySpecificIdent(String)}. * @@ -1070,7 +1100,7 @@ * 'specified_name' ::= 'db_tablename' '.' 'db_attributename' */ public void getSingleRowAttrsSpec(Map result, ResultSet rs) - throws SQLException + throws SQLException { ResultSetMetaData rsmd = rs.getMetaData(); int numCols = rsmd.getColumnCount(); |
|
From: Michael K. <ko...@us...> - 2005-08-22 13:52:15
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17565/org/cobricks/core/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- DBAccessImpl.java 10 Aug 2005 13:31:33 -0000 1.18 +++ DBAccessImpl.java 22 Aug 2005 13:52:06 -0000 1.19 @@ -1300,6 +1300,9 @@ if (coltype.startsWith("String")) { return "varchar"+coltype.substring(6); } + if (dbtype==DBTYPE_MYSQL && coltype.equalsIgnoreCase("timestamp")) { + return "datetime"; + } if (dbtype==DBTYPE_MYSQL && coltype.equalsIgnoreCase("clob")) { return "text"; } |
|
From: Michael K. <ko...@us...> - 2005-11-29 07:18:46
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2355/org/cobricks/core/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- DBAccessImpl.java 21 Oct 2005 15:56:46 -0000 1.20 +++ DBAccessImpl.java 29 Nov 2005 07:18:38 -0000 1.21 @@ -1024,7 +1024,10 @@ result.put(label.toLowerCase(), ts); continue; } catch (Exception e) { - Object o = rs.getObject(i); + Object o = null; + try { // if this failes, it is a representation of NULL + o = rs.getObject(i); + } catch (Exception e2) { } if (o != null) { logger.warn("Failed reading timestamp value from: " +o.toString()+" "+o.getClass().getName()); |
|
From: Michael K. <ko...@us...> - 2005-12-13 17:07:58
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28259 Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- DBAccessImpl.java 13 Dec 2005 09:05:02 -0000 1.22 +++ DBAccessImpl.java 13 Dec 2005 17:07:39 -0000 1.23 @@ -92,6 +92,7 @@ String jdbcUri = p.getProperty("db.jdbc.uri"); if (jdbcUri.startsWith("jdbc:mysql")) dbtype = DBTYPE_MYSQL; if (jdbcUri.startsWith("jdbc:postgresql")) dbtype = DBTYPE_POSTGRES; + if (jdbcUri.startsWith("jdbc:oracle")) dbtype = DBTYPE_ORACLE; String jdbcUser = p.getProperty("db.jdbc.user"); String jdbcPw = p.getProperty("db.jdbc.pw"); @@ -846,6 +847,7 @@ try { conn = dataSource.getConnection(); stmt = conn.createStatement(); + if (dbtype == DBTYPE_ORACLE) stmt.setEscapeProcessing(false); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { if (maxRows == 0) break; @@ -932,6 +934,7 @@ try { conn = dataSource.getConnection(); stmt = conn.createStatement(); + if (dbtype == DBTYPE_ORACLE) stmt.setEscapeProcessing(false); ResultSet rs = stmt.executeQuery(sql); if (rs.next()) { getSingleRowAttributes(result, rs); @@ -965,6 +968,7 @@ try { conn = dataSource.getConnection(); stmt = conn.createStatement(); + if (dbtype == DBTYPE_ORACLE) stmt.setEscapeProcessing(false); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { Map result2 = new HashMap(); @@ -1183,6 +1187,7 @@ try { conn = dataSource.getConnection(); stmt = conn.createStatement(); + if (dbtype == DBTYPE_ORACLE) stmt.setEscapeProcessing(false); stmt.executeUpdate(sql); } catch(Exception e) { logger.error(LogUtil.ex("Failed executing sql statement: "+sql, e)); @@ -1305,29 +1310,35 @@ if (coltype.startsWith("String")) { return "varchar"+coltype.substring(6); } - if (dbtype==DBTYPE_MYSQL && coltype.equalsIgnoreCase("timestamp")) { - return "datetime"; - } - if (dbtype==DBTYPE_MYSQL && coltype.equalsIgnoreCase("clob")) { - return "text"; - } - if (dbtype==DBTYPE_MYSQL && coltype.equalsIgnoreCase("binary")) { - return "blob"; - } - if (dbtype==DBTYPE_ORACLE && coltype.equalsIgnoreCase("binary")) { - return "blob"; - } - if (dbtype==DBTYPE_ORACLE && coltype.equalsIgnoreCase("text")) { - return "clob"; - } - if (dbtype==DBTYPE_POSTGRES && coltype.equalsIgnoreCase("clob")) { - return "text"; + if (dbtype==DBTYPE_MYSQL) { + if (coltype.equalsIgnoreCase("timestamp")) { + return "datetime"; + } + if (coltype.equalsIgnoreCase("clob")) { + return "text"; + } + if (coltype.equalsIgnoreCase("binary")) { + return "blob"; + } } - if (dbtype==DBTYPE_POSTGRES && coltype.equalsIgnoreCase("binary")) { - return "bytea"; + if (dbtype==DBTYPE_POSTGRES) { + if (coltype.equalsIgnoreCase("clob")) { + return "text"; + } + if (coltype.equalsIgnoreCase("binary")) { + return "bytea"; + } + if (coltype.equalsIgnoreCase("blob")) { + return "bytea"; + } } - if (dbtype==DBTYPE_POSTGRES && coltype.equalsIgnoreCase("blob")) { - return "bytea"; + if (dbtype==DBTYPE_ORACLE) { + if (coltype.equalsIgnoreCase("binary")) { + return "blob"; + } + if (coltype.equalsIgnoreCase("text")) { + return "clob"; + } } return coltype; } |
|
From: Michael K. <ko...@us...> - 2005-12-20 18:10:32
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23729/cobricks/core/db Modified Files: DBAccessImpl.java Log Message: Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- DBAccessImpl.java 13 Dec 2005 17:07:39 -0000 1.23 +++ DBAccessImpl.java 20 Dec 2005 18:10:24 -0000 1.24 @@ -1294,6 +1294,11 @@ // check which version of the table is in the database // if it is not the newest, then update + // MYSQL: + // ALTER TABLE xxx CHANGE `x` y ytype + // Postgres: + // ALTER TABLE xxx RENAME COLUMN x TO y + return true; } |
|
From: Michael K. <ko...@us...> - 2006-05-24 09:03:09
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8047 Modified Files: DBAccessImpl.java Log Message: Corrected problems with PorstgreSQL database server (which does not automatically convert String to column types) Index: DBAccessImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/core/db/DBAccessImpl.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- DBAccessImpl.java 3 Jan 2006 09:35:20 -0000 1.25 +++ DBAccessImpl.java 24 May 2006 09:02:55 -0000 1.26 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2005 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -23,6 +23,7 @@ import org.cobricks.core.CobricksException; import org.cobricks.core.CoreManager; +import org.cobricks.core.util.DateUtil; import org.cobricks.core.util.LogUtil; import org.cobricks.core.util.ResourceUtil; @@ -393,16 +394,26 @@ String aname = (String)i.next(); String type = td.getColumnType(aname); Object o = attrs.get(aname); - if (o == null) - logger.debug("setPrepared "+aname+": NULL"); - else - logger.debug("setPrepared "+aname+": "+o.getClass().getName()); + if (o == null) { + logger.debug("setPrepared "+count+" "+aname+": NULL"); + } else { + if (type.equals("timestamp") && (o instanceof String)) { + // some converting is needed ... + o = DateUtil.string2Date((String)o); + } else + if (type.equals("int") && (o instanceof String)) { + // some converting is needed ... + o = new Integer((String)o); + } + logger.debug("setPrepared "+count+" "+type+" "+aname+": " + +o.getClass().getName()); + } // is the parameter a Set? - then convert it to a String - // tbd ... not perfect yes + // tbd ... not perfect yet if (o instanceof Set) { o = setToString((Set)o); } - count += setPreparedObject(pstmt, o, count); + count = count + setPreparedObject(pstmt, o, count); } } @@ -482,6 +493,15 @@ else if (o instanceof java.sql.Time) { pstmt.setTime(position, (java.sql.Time)o); } + else if (o instanceof java.lang.Integer) { + pstmt.setInt(position, ((java.lang.Integer)o).intValue()); + } + else if (o instanceof java.lang.Float) { + pstmt.setFloat(position, ((java.lang.Float)o).floatValue()); + } + else if (o instanceof java.lang.Long) { + pstmt.setLong(position, ((java.lang.Long)o).longValue()); + } else if (o instanceof byte[]) { pstmt.setBytes(position, (byte[])o); } |