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:test.Test_db.java
public void test() throws SQLException, ClassNotFoundException { String string = "vnws?"; ByteArrayInputStream bain = new ByteArrayInputStream(string.getBytes()); System.out.println(string.getBytes().length); Class.forName("org.postgresql.Driver"); String url = "jdbc:postgresql://localhost:5432/free-choice-v1"; String url1 = "jdbc:postgresql://localhost:5432/test"; Connection conn = DriverManager.getConnection(url, "bcgh2013", "2013.bcgh.start"); // Connection conn = cpds.getConnection(); PreparedStatement ps = conn.prepareStatement("insert into psw(bs128)values(?)"); ps.setBinaryStream(1, bain);//from w w w .ja v a 2s . com // ps.setBytes(1, string.getBytes()); ps.execute(); // ps.setObject(1, string.getBytes(), POst) conn.close(); }
From source file:hr.fer.zemris.vhdllab.dao.impl.AbstractOwnedEntityDaoTest.java
private OwnedEntityTable setupOwnedEntity(final String userId, final String name) { String query = createInsertStatement("OwnedEntityTable", "id, version, user_id, name", "null, 0, ?, ?"); getJdbcTemplate().execute(query, new PreparedStatementCallback() { @Override//ww w . j av a 2 s . c o m public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.setString(1, userId); ps.setString(2, name); return ps.execute(); } }); return new OwnedEntityTable(userId, name); }
From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java
@Override public void delete(long parentId, int week) { jdbcTemplate.execute("DELETE FROM schedule WHERE parent_id = ? AND week = ?", (PreparedStatement preparedStatement) -> { preparedStatement.setLong(1, parentId); preparedStatement.setInt(2, week); preparedStatement.execute(); return null; });//from w ww. j a va 2 s. co m }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminRepairChar.java
private void handleRepair(String command, L2Player activeChar) { String[] parts = command.split(" "); if (parts.length != 2) return;/* w ww . j ava 2 s .c o m*/ final Integer objId = CharNameTable.getInstance().getByName(parts[1]); if (objId == 0) return; Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("UPDATE characters SET x=17867, y=170259, z=-3450 WHERE charId=?"); statement.setInt(1, objId); statement.execute(); statement.close(); statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?"); statement.setInt(1, objId); statement.execute(); statement.close(); statement = con .prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=? AND loc=\"PAPERDOLL\""); statement.setInt(1, objId); statement.execute(); statement.close(); activeChar.sendMessage("Character " + parts[1] + " got repaired."); } catch (Exception e) { _log.warn("Could not repair character: ", e); } finally { L2DatabaseFactory.close(con); } }
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 w w . ja v a2 s. c om*/ ps.setInt(2, attempts); ps.setString(3, sessionId); log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } }
From source file:com.wso2.raspberrypi.Util.java
public static void registerRaspberryPi(String macAddress, String ipAddress) { System.out.println("Registering Raspberry Pi: " + macAddress + "/" + ipAddress); BasicDataSource ds = getBasicDataSource(); Connection dbConnection = null; PreparedStatement prepStmt = null; ResultSet rs = null;/* www . ja va 2 s. co m*/ try { dbConnection = ds.getConnection(); prepStmt = dbConnection.prepareStatement("SELECT * FROM RASP_PI WHERE mac='" + macAddress + "'"); rs = prepStmt.executeQuery(); if (rs.next()) { // If it exists prepStmt = dbConnection.prepareStatement("UPDATE RASP_PI SET ip='" + ipAddress + "',last_updated='" + System.currentTimeMillis() + "' WHERE mac='" + macAddress + "'"); prepStmt.executeUpdate(); } else { prepStmt = dbConnection.prepareStatement("INSERT INTO RASP_PI (mac,ip,last_updated) VALUES ('" + macAddress + "','" + ipAddress + "','" + System.currentTimeMillis() + "' )"); prepStmt.execute(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (dbConnection != null) { dbConnection.close(); } if (prepStmt != null) { prepStmt.close(); } if (rs != null) { rs.close(); } } catch (SQLException e) { e.printStackTrace(); } } }
From source file:com.fpmislata.banco.persistencia.impl.SucursalBancariaDAOImplJDBC.java
@Override public void delete(int id) { Connection connection = connectionFactory.getConnection(); String SQL = "DELETE FROM sucursalbancaria WHERE id=?"; try {// w ww . java2 s . c o m PreparedStatement preparedStatement = connection.prepareStatement(SQL); preparedStatement.setInt(1, id); preparedStatement.execute(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { connection.close(); } catch (Exception ex) { throw new RuntimeException(ex); } } }
From source file:com.l2jfree.gameserver.datatables.RecordTable.java
public synchronized void update() { final int onlinePlayerCount = L2World.getInstance().getAllPlayersCount(); if (_record < onlinePlayerCount) { Connection con = null;// w w w. j a v a 2 s. c om try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("INSERT INTO record (maxplayer, date) VALUES (?, NOW())"); statement.setInt(1, onlinePlayerCount); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } load(); } }
From source file:com.l2jfree.gameserver.instancemanager.ItemsOnGroundManager.java
public void emptyTable() { Connection con = null;/* w w w . j a v a2s .com*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement del = con.prepareStatement("DELETE from itemsonground"); del.execute(); del.close(); } catch (Exception e1) { _log.fatal("error while cleaning table ItemsOnGround " + e1, e1); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.instancemanager.BlockListManager.java
public synchronized void remove(L2Player listOwner, String name) { Connection con = null;//ww w . java2 s.c o m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(DELETE_QUERY); statement.setInt(1, listOwner.getObjectId()); statement.setString(2, name); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } }