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 updates the variable "isActive" in the database. The variable * "isActive" is a column of the table "OutputDevices". With this method the * output devices can notify if they are active and like to get messages or * not./* w ww . j a v a2s. com*/ * * @param classes * class of the output device * @param name * name of the output device * @param active * true= is active and like to get messages false=is not active * and does not listen to messages */ @GET @Path("/isActive/{classes}/{name}/{isActive}") public synchronized static String isActive(@PathParam("classes") String classes, @PathParam("name") String name, @PathParam("isActive") String active) { createDBConnection(); String ok = "ok"; PreparedStatement st; try { boolean isActive = false; if (active.equals("t")) { isActive = true; } st = conn.prepareStatement("update \"OutputDevices\" set enabled=? where \"class\"=? and \"topic\"=?;"); st.setBoolean(1, isActive); st.setString(2, classes); st.setString(3, name); st.execute(); if (st.getUpdateCount() != 1) { ok = "class or topic not found"; } else { deviceActive.put(classes + "," + name, isActive); } } catch (SQLException e) { logger.error("SQL Exception in Method isActive", e); } closeDBConnection(); return ok; }
From source file:com.l2jfree.gameserver.datatables.ClanTable.java
public void deleteclanswars(int clanId1, int clanId2) { L2Clan clan1 = ClanTable.getInstance().getClan(clanId1); L2Clan clan2 = ClanTable.getInstance().getClan(clanId2); clan1.deleteEnemyClan(clan2);//from w w w . j a v a 2 s. c om clan2.deleteEnemyClan(clan1); clan1.broadcastClanStatus(); clan2.broadcastClanStatus(); Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?"); statement.setInt(1, clanId1); statement.setInt(2, clanId2); statement.execute(); statement.close(); } catch (Exception e) { _log.error("could not restore clans wars data:", e); } finally { L2DatabaseFactory.close(con); } SystemMessage msg = new SystemMessage(SystemMessageId.WAR_AGAINST_S1_HAS_STOPPED); msg.addString(clan2.getName()); clan1.broadcastToOnlineMembers(msg); msg = new SystemMessage(SystemMessageId.CLAN_S1_HAS_DECIDED_TO_STOP); msg.addString(clan1.getName()); clan2.broadcastToOnlineMembers(msg); }
From source file:com.splicemachine.mrio.api.core.SMSQLUtil.java
public void commitChildTransaction(Connection conn, long childTxnID) throws SQLException { PreparedStatement ps = conn.prepareStatement("call SYSCS_UTIL.SYSCS_COMMIT_CHILD_TRANSACTION(?)"); ps.setLong(1, childTxnID);//ww w .j a v a 2 s . c o m ps.execute(); }
From source file:com.tacitknowledge.util.migration.jdbc.PatchTable.java
/** * {@inheritDoc}// w w w. j av a 2 s .co m */ public void updatePatchLevel(int level) throws MigrationException { // Make sure a patch record already exists for this system getPatchLevel(); Connection conn = null; PreparedStatement stmt = null; try { conn = context.getConnection(); stmt = conn.prepareStatement(getSql("level.update")); stmt.setInt(1, level); stmt.setString(2, context.getSystemName()); stmt.execute(); context.commit(); } catch (SQLException e) { throw new MigrationException("Unable to update patch level", e); } finally { SqlUtil.close(conn, stmt, null); } }
From source file:dk.netarkivet.harvester.datamodel.PostgreSQLSpecifics.java
/** * Get a temporary table for short-time use. The table should be disposed of * with dropTemporaryTable. The table has two columns domain_name * varchar(Constants.MAX_NAME_SIZE) config_name * varchar(Constants.MAX_NAME_SIZE)//from w ww . ja va 2 s .c om * * @param c * The DB connection to use. * @throws SQLException * if there is a problem getting the table. * @return The name of the created table */ public String getJobConfigsTmpTable(Connection c) throws SQLException { ArgumentNotValid.checkNotNull(c, "Connection c"); PreparedStatement s = c.prepareStatement( "CREATE TEMPORARY TABLE " + "jobconfignames " + "( domain_name varchar(" + Constants.MAX_NAME_SIZE + "), " + " config_name varchar(" + Constants.MAX_NAME_SIZE + ") ) ON COMMIT DROP"); s.execute(); s.close(); return "jobconfignames"; }
From source file:mx.com.pixup.portal.dao.FormaPagoDaoJdbc.java
@Override public FormaPago insertFormaPago(FormaPago formaPago) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null;/*from w w w .java 2s . c o m*/ String sql = "insert into forma_pago (descripcion) values (?)"; try { connection = dataSource.getConnection(); connection.setAutoCommit(false); preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, formaPago.getDescripcion()); preparedStatement.execute(); connection.commit(); resultSet = preparedStatement.getGeneratedKeys(); resultSet.next(); formaPago.setId(resultSet.getInt(1)); return formaPago; } catch (Exception e) { } finally { if (preparedStatement != null) { try { preparedStatement.close(); } catch (Exception e) { } } if (connection != null) { try { connection.close(); } catch (Exception e) { } } } return null; }
From source file:Controllers.AppointmentController.java
/** * * @param appointment/* www . j av a 2s. co m*/ * @param result * @param modelMap * @return */ @RequestMapping(method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) public String AddApp(@ModelAttribute("appointment") Appointment appointment, BindingResult result, ModelMap modelMap) { int accountId = appointment.getAccountId(); int departmentId = appointment.getDepartmentId(); Date fulldate = appointment.getDate(); java.sql.Date date = new java.sql.Date(fulldate.getTime()); String message = appointment.getMessage(); String content = ""; if (departmentId == 0 || date == null) { content = "Sorry, you didn't fill some of fields. Please, try again."; modelMap.addAttribute("content", content); return "appointmentConfirmation"; } Date m = null; int appointmentcounter = 0; Appointment[] appointments = fetchAppointments(); for (int i = 0; i < appointments.length; i++) { if (appointments[i].getDate().compareTo(date) == 0 && appointments[i].getDepartmentId() == departmentId) appointmentcounter++; } if (appointmentcounter >= 2) { content = "Sorry, there is no any free spaces for your appointment on " + date + " to visit " + findDepartmentName(departmentId) + ". Please, select another day.<br>"; modelMap.addAttribute("content", content); return "appointmentConfirmation"; } try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("jdbc/medicalCareDataSource"); connection = ds.getConnection(); Statement stmt = connection.createStatement(); PreparedStatement pstmt; pstmt = connection.prepareStatement( "INSERT INTO appointments (accountId, departmentId, date, message)\n" + "VALUES (?,?,?,?);"); pstmt.setInt(1, accountId); pstmt.setInt(2, departmentId); pstmt.setDate(3, date); pstmt.setString(4, message); pstmt.execute(); content = "<h4>Appontment have been setted.</h4><br><h5>Please, check information below.</h5><br>" + "<table>" + "<tr><td>Seleted department:</td><td>" + findDepartmentName(departmentId) + "</td></tr>" + "<tr><td>Seleted date:</td><td>" + new SimpleDateFormat("yyyy-MM-dd").format(date) + "</td></tr>" + "<tr><td>Attached message</td><td>" + message + "</td></tr>" + "</table>"; stmt.close(); } catch (NamingException ex) { Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex); } modelMap.addAttribute("content", content); return "appointmentConfirmation"; }
From source file:com.chenxin.authority.common.logback.DBAppender.java
/** * Add an exception statement either as a batch or execute immediately if * batch updates are not supported.//w w w . j a v a 2 s. com */ void updateExceptionStatement(PreparedStatement exceptionStatement, String txt, short i, long eventId) throws SQLException { exceptionStatement.setLong(1, eventId); exceptionStatement.setShort(2, i); exceptionStatement.setString(3, txt); if (cnxSupportsBatchUpdates) { exceptionStatement.addBatch(); } else { exceptionStatement.execute(); } }
From source file:com.tacitknowledge.util.migration.jdbc.PatchTable.java
public void updatePatchLevelAfterRollBack(int rollbackLevel) throws MigrationException { // Make sure a patch record already exists for this system getPatchLevel();/* ww w . j a va 2 s. co m*/ Connection conn = null; PreparedStatement stmt = null; try { conn = context.getConnection(); stmt = conn.prepareStatement(getSql("level.rollback")); stmt.setInt(1, rollbackLevel); stmt.setString(2, context.getSystemName()); stmt.execute(); context.commit(); } catch (SQLException e) { throw new MigrationException("Unable to update patch level", e); } finally { SqlUtil.close(conn, stmt, null); } }