List of usage examples for java.sql PreparedStatement toString
public String toString()
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static String insertAuthFlowStatus(String username, String status, String uuid) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "INSERT INTO `regstatus` (`uuid`,`username`, `status`) VALUES (?,?,?);"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, uuid);/*from www .j a v a 2 s . com*/ ps.setString(2, username); ps.setString(3, status); log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } return uuid; }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void insertPinAttempt(String msisdn, int attempts, String sessionId) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "insert into multiplepasswords(username, attempts, ussdsessionid) values (?,?,?);"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, msisdn);//from w ww.j av a 2s .c o m ps.setInt(2, attempts); ps.setString(3, sessionId); log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } }
From source file:net.spfbl.core.Server.java
/** * Registra as mensagens de manipulao do banco de dados. * @param statement the statement executed. *//* w w w . j a v a2s . c om*/ public static void logMySQL(long time, PreparedStatement statement, String result) { String message = statement.toString(); int beginIndex = message.indexOf(' ') + 1; int endIndex = message.length(); message = message.substring(beginIndex, endIndex); log(time, Core.Level.DEBUG, "MYSQL", message, result); }
From source file:net.spfbl.core.Server.java
/** * Registra as mensagens de manipulao do banco de dados. * @param statement the statement executed. */// w w w . ja v a 2 s . c o m public static void logMySQL(long time, PreparedStatement statement, SQLException ex) { String message = statement.toString(); int beginIndex = message.indexOf(' ') + 1; int endIndex = message.length(); message = message.substring(beginIndex, endIndex); String result = "ERROR " + ex.getErrorCode() + " " + ex.getMessage(); log(time, Core.Level.DEBUG, "MYSQL", message, result); }
From source file:org.mifos.client.repository.PersistentLocalDateTest.java
private void verifyPersistentLocalDate(String expectedDate) throws MifosException, SQLException { LocalDate localDate = new LocalDate(expectedDate); PersistentLocalDate persistentLocalDate = new PersistentLocalDate(); Connection connection = dataSource.getConnection(); try {/* w ww .j a va2 s . co m*/ PreparedStatement preparedStatement = connection .prepareStatement("insert into clients (dateOfBirth, firstName, lastName) values (?, ?, ?)"); persistentLocalDate.nullSafeSet(preparedStatement, localDate, 1); String[] statementParts = preparedStatement.toString().split(" "); String actualDate = statementParts[8]; actualDate = actualDate.replaceAll("\\(", ""); actualDate = actualDate.replaceAll("'", ""); actualDate = actualDate.replaceAll(",", ""); Assert.assertEquals(actualDate, expectedDate); } finally { connection.close(); } }
From source file:uk.ac.cam.cl.dtg.segue.dao.associations.PgAssociationDataManager.java
@Override public void deleteToken(final String token) throws SegueDatabaseException { if (null == token || token.isEmpty()) { throw new SegueDatabaseException("Unable to locate the token requested to delete."); }/* w ww . j a v a 2 s. co m*/ try (Connection conn = database.getDatabaseConnection()) { PreparedStatement pst; pst = conn.prepareStatement("DELETE FROM user_associations_tokens WHERE token = ?"); log.debug(pst.toString()); pst.setString(1, token); pst.execute(); } catch (SQLException e1) { throw new SegueDatabaseException("Postgres exception", e1); } }
From source file:broadwick.data.readers.DataFileReader.java
/** * Perform the insertion into the database. * @param connection the connection to the database. * @param tableName the name of the table into which the data will be put. * @param insertString the command used to insert a row into the database. * @param dataFile the [CSV] file that contained the data. * @param dateFormat the format of the date in the file. * @param insertedColInfo a map of column name to column in the data file. * @param dateFields a collection of columns in the csv file that contains date fields. * @return the number of rows inserted.//from w ww.j av a2 s . c om */ protected final int insert(final Connection connection, final String tableName, final String insertString, final String dataFile, final String dateFormat, final Map<String, Integer> insertedColInfo, final Collection<Integer> dateFields) { int inserted = 0; try { // Now do the insertion. log.trace("Inserting into {} via {}", tableName, insertString); PreparedStatement pstmt = connection.prepareStatement(insertString); log.trace("Prepared statement = {}", pstmt.toString()); try (FileInput instance = new FileInput(dataFile, ",")) { final StopWatch sw = new StopWatch(); sw.start(); List<String> data = instance.readLine(); while (data != null && !data.isEmpty()) { int parameterIndex = 1; for (Map.Entry<String, Integer> entry : insertedColInfo.entrySet()) { if (entry.getValue() == -1) { pstmt.setObject(parameterIndex, null); } else { final String value = data.get(entry.getValue() - 1); if (dateFields.contains(entry.getValue())) { int dateField = Integer.MAX_VALUE; if (value != null && !value.isEmpty()) { dateField = BroadwickConstants.getDate(value, dateFormat); } pstmt.setObject(parameterIndex, dateField); } else { pstmt.setObject(parameterIndex, value); } } parameterIndex++; } pstmt.addBatch(); try { pstmt.executeUpdate(); inserted++; } catch (SQLException ex) { if ("23505".equals(ex.getSQLState())) { //Ignore found duplicate from database view continue; } else { log.warn("Duplicate data found for {}: continuing despite errors: {}", data.get(0), ex.getLocalizedMessage()); log.trace("{}", Throwables.getStackTraceAsString(ex)); throw ex; } } if (inserted % 250000 == 0) { log.trace("Inserted {} rows in {}", inserted, sw.toString()); connection.commit(); pstmt.close(); pstmt = connection.prepareStatement(insertString); } data = instance.readLine(); } connection.commit(); } catch (IOException ex) { log.error("IO error : {}", ex.getLocalizedMessage()); log.trace("{}", Throwables.getStackTraceAsString(ex)); } catch (SQLException ex) { log.error("SQL Error : {}", ex.getLocalizedMessage()); log.trace("{}", Throwables.getStackTraceAsString(ex)); throw ex; } finally { pstmt.close(); } } catch (SQLException ex) { log.error("{}", ex.getLocalizedMessage()); log.trace("{}", Throwables.getStackTraceAsString(ex)); throw new BroadwickException(ex); } return inserted; }
From source file:org.tec.webapp.jdbc.entity.support.IdentifierCallback.java
/** {@inheritDoc} */ @Override()// w w w. ja v a 2 s . c om public Long doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ResultSet generatedKeys = null; try { ps.execute(); generatedKeys = ps.getGeneratedKeys(); if (generatedKeys.next()) { return Long.valueOf(generatedKeys.getLong(1)); } else { throw new SQLException("Unable to insert new record " + ps.toString()); } } finally { if (generatedKeys != null) { generatedKeys.close(); } } }
From source file:Database.Handler.java
public int updateQuery(String sql, String[] para) { PreparedStatement ps; int res = -1; //return result try {//from w ww . ja v a2 s. c o m Connection c = DriverManager.getConnection(DbConfig.connectionString, DbConfig.dbUserName, DbConfig.dbPassword); ps = c.prepareStatement(sql); System.out.println(ps.toString()); for (int i = 0; i < para.length; i++) { ps.setString(i + 1, para[i]); } System.out.println(ps.toString()); int result = ps.executeUpdate(); res = (result != 0) ? 1 : -1; return res; } catch (SQLException ex) { System.out.println("Handler updateQuery error:" + ex.getMessage()); return res; } }
From source file:storybook.model.oldModel.ModelMigration.java
/** * Closes the prepare statement/*from w w w.java 2 s .c o m*/ * * @param prepare The PreparedStatement that needs to close */ public void closePrepareStatement(PreparedStatement prepare) { try { if (prepare != null) { prepare.close(); } } catch (SQLException se) { SbApp.error("*** ModelMigration.closePrepareStatement(" + prepare.toString() + ")", se); } }