List of usage examples for java.sql PreparedStatement execute
boolean execute() throws SQLException;
PreparedStatement
object, which may be any kind of SQL statement. From source file:de.klemp.middleware.controller.Controller.java
/** * This method searches the methods from the classes of the first and the * second component. If a method of the second component needs a data, then * the String "Struktur fehlt" will be set in the column "data" of the table * "Classes". If a method does not need a data the column data is set="". */// w w w . j a v a 2 s.c om public static synchronized void searchMethods() { createDBConnection(); try { Statement statement = conn.createStatement(); statement.execute("delete from \"Classes\";"); statement.execute("delete from \"Data\";"); structures.clear(); PreparedStatement st = conn .prepareStatement("insert into \"Classes\" (component, class, method) values (?,?,?); "); ArrayList classes = getClasses(component1); Iterator iterator = classes.iterator(); st.setInt(1, 1); while (iterator.hasNext()) { Object class1 = iterator.next(); Method[] methods = class1.getClass().getDeclaredMethods(); String name1 = class1.getClass().getName(); String[] className = name1.split("\\."); st.setString(2, className[1]); for (int i = 0; i < methods.length; i++) { String name = methods[i].getName(); st.setString(3, name); st.execute(); } } classes = getClasses(component2); iterator = classes.iterator(); st.setInt(1, 2); PreparedStatement st2 = conn .prepareStatement("insert into \"Data\" ( class, method,topic,data) values (?,?,?,?); "); while (iterator.hasNext()) { Object class2 = iterator.next(); Method[] methods = class2.getClass().getDeclaredMethods(); String name2 = class2.getClass().getName(); String[] className = name2.split("\\."); st.setString(2, className[1]); st2.setString(1, className[1]); for (int i = 0; i < methods.length; i++) { String method = methods[i].getName(); st2.setString(3, ""); st.setString(3, method); st2.setString(2, method); Class<?>[] parameter = methods[i].getParameterTypes(); for (int j = 0; j < parameter.length; j++) { if (parameter[j].getName() == "Controller.Structure") { st2.setString(4, "structure is missing"); st2.execute(); break; } if (parameter[j].getName() == "Controller.Sensor") { st2.setString(4, "Sensor"); st2.execute(); break; } } st.execute(); } } } catch (SQLException e) { logger.error("SQL Exception", e); } closeDBConnection(); }
From source file:com.wso2telco.workflow.dao.WorkflowStatsDbService.java
public void insertSubApprovalAuditRecord(SubscriptionApprovalAuditRecord record) throws SQLException, BusinessException { Connection conn = null;//from w w w . j av a 2s .c o m PreparedStatement ps = null; try { conn = dbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); StringBuilder query = new StringBuilder(); query.append("INSERT INTO sub_approval_audit (API_PROVIDER, API_NAME, API_VERSION, APP_ID, "); query.append("SUB_STATUS, SUB_APPROVAL_TYPE, COMPLETED_BY_ROLE, COMPLETED_BY_USER) "); query.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); ps = conn.prepareStatement(query.toString()); ps.setString(1, record.getApiProvider()); ps.setString(2, record.getApiName()); ps.setString(3, record.getApiVersion()); ps.setInt(4, record.getAppId()); ps.setString(5, record.getSubStatus()); ps.setString(6, record.getSubApprovalType()); ps.setString(7, record.getCompletedByRole()); ps.setString(8, record.getCompletedByUser()); ps.execute(); } catch (SQLException e) { throw new SQLException(); } catch (Exception e) { throw new BusinessException(GenaralError.UNDEFINED); } finally { dbUtils.closeAllConnections(ps, conn, null); } }
From source file:mysql5.MySQL5PlayerDAO.java
/** * {@inheritDoc}/*from w w w. jav a 2s .c o m*/ */ @Override public void updateDeletionTime(final int objectId, final Timestamp deletionDate) { DB.insertUpdate("UPDATE players set deletion_date = ? where id = ?", new IUStH() { @Override public void handleInsertUpdate(PreparedStatement preparedStatement) throws SQLException { preparedStatement.setTimestamp(1, deletionDate); preparedStatement.setInt(2, objectId); preparedStatement.execute(); } }); }
From source file:mysql5.MySQL5PlayerDAO.java
/** * {@inheritDoc}//w w w. j a v a 2 s . co m */ @Override public void storeCreationTime(final int objectId, final Timestamp creationDate) { DB.insertUpdate("UPDATE players set creation_date = ? where id = ?", new IUStH() { @Override public void handleInsertUpdate(PreparedStatement preparedStatement) throws SQLException { preparedStatement.setTimestamp(1, creationDate); preparedStatement.setInt(2, objectId); preparedStatement.execute(); } }); }
From source file:mysql5.MySQL5PlayerDAO.java
/** * {@inheritDoc}//from w w w.j av a 2 s . c om */ @Override public void changePlayerId(final Player player, final int accountId) { Connection con = null; try { con = DatabaseFactory.getConnection(); PreparedStatement stmt = con.prepareStatement("UPDATE players SET account_id=? WHERE id=?"); stmt.setInt(1, accountId); stmt.setInt(2, player.getObjectId()); stmt.execute(); stmt.close(); } catch (Exception e) { log.error("Error saving player: " + player.getObjectId() + " " + player.getName(), e); } finally { DatabaseFactory.close(con); } }
From source file:com.mirth.connect.connectors.jdbc.DatabaseDispatcherQuery.java
@Override public Response send(DatabaseDispatcherProperties connectorProperties, ConnectorMessage connectorMessage) throws DatabaseDispatcherException { long dispatcherId = connector.getDispatcherId(); SimpleDataSource dataSource = dataSources.get(dispatcherId); if (dataSource == null) { dataSource = new SimpleDataSource(); dataSources.put(dispatcherId, dataSource); }/*from w ww . j a v a 2s. c o m*/ PreparedStatement statement = null; try { Connection connection = dataSource.getConnection(connectorProperties); statement = connection.prepareStatement(connectorProperties.getQuery()); int i = 1; for (Object param : connectorProperties.getParameters()) { statement.setObject(i++, param); } /* * We do not use Statement.executeUpdate() here because it could prevent users from * executing a stored procedure. Executing a stored procedure in Postgres (and possibly * other databases) is done via SELECT myprocedure(), which breaks executeUpdate() since * it returns a result, even if the procedure itself returns void. */ statement.execute(); int numRows = statement.getUpdateCount(); String responseData = null; String responseMessageStatus = null; if (numRows == -1) { responseMessageStatus = "Database write success"; } else { responseMessageStatus = "Database write success, " + numRows + " rows updated"; } return new Response(Status.SENT, responseData, responseMessageStatus); } catch (Exception e) { throw new DatabaseDispatcherException("Failed to write to database", e); } finally { DbUtils.closeQuietly(statement); } }