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:com.sapienter.jbilling.tools.ConvertToBinHexa.java
private static ResultSet getUserRowsToUpdate() throws SQLException { PreparedStatement stmt = connection.prepareStatement("SELECT u.ID, u.password" + " FROM base_user u, user_role_map r " + " where u.id = r.user_id " + " and r.role_id < 3 "); stmt.execute(); return stmt.getResultSet(); }
From source file:com.sapienter.jbilling.tools.ConvertToBinHexa.java
private static ResultSet getCCRowsToUpdate() throws SQLException { PreparedStatement stmt = connection.prepareStatement("SELECT c.ID, c.name, c.cc_number, m.user_id" + " FROM credit_card c, user_credit_card_map m " + " WHERE c.id = m.credit_card_id"); stmt.execute(); return stmt.getResultSet(); }
From source file:com.sql.DBBackupScript.java
/** * Backup database command//from www.j a v a 2s . co m * * @param databaseName String */ public static void backupDB(String databaseName) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDBforBackup(); String sql = "BACKUP DATABASE " + databaseName + " TO DISK = '" + Global.getDatabaseBackupPath() + "' "; ps = conn.prepareStatement(sql); ps.execute(); } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(ps); DbUtils.closeQuietly(conn); } }
From source file:com.buddycloud.friendfinder.HashUtils.java
public static boolean reportHash(String jid, String hash, ComponentDataSource dataSource) { if (retrieveJid(hash, dataSource) != null) { return false; }// www .j a v a2 s . c o m PreparedStatement statement = null; try { statement = dataSource.prepareStatement( "INSERT INTO \"contact-matches\"(\"credential-hash\", \"jid\") VALUES (?, ?)", hash, jid); statement.execute(); return true; } catch (SQLException e) { LOGGER.error("Could not report hash " + hash + " for jid " + jid, e); throw new RuntimeException(e); } finally { ComponentDataSource.close(statement); } }
From source file:io.apiman.gateway.engine.jdbc.JdbcMetricsTest.java
/** * Initialize the DB with the apiman gateway DDL. * @param connection/*from ww w. j av a 2 s. co m*/ */ private static void initDB(Connection connection) throws Exception { ClassLoader cl = JdbcMetricsTest.class.getClassLoader(); URL resource = cl.getResource("ddls/apiman-gateway_h2.ddl"); try (InputStream is = resource.openStream()) { System.out.println("======================================="); System.out.println("Initializing database."); DdlParser ddlParser = new DdlParser(); List<String> statements = ddlParser.parse(is); for (String sql : statements) { System.out.println(sql); PreparedStatement statement = connection.prepareStatement(sql); statement.execute(); } System.out.println("======================================="); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.TopicDaoImplTest.java
@AfterClass public static void cleanupDatabase() throws Exception { final String statementStr1 = "DELETE FROM ofPubsubNode WHERE nodeID LIKE '%" + NODE_PREFIX + "%'"; Connection conn = null;/*www. j av a 2 s .c o m*/ PreparedStatement pstmt1 = null; try { conn = UnitTestDSProvider.getDataSource().getConnection(); pstmt1 = conn.prepareStatement(statementStr1); pstmt1.execute(); } catch (SQLException e) { LOGGER.error("cleanupDatabase : {}", e); } finally { CloseUtil.close(LOGGER, pstmt1, conn); } }
From source file:ch.newscron.encryption.ReferralManagerJUnitTest.java
@AfterClass public static void tearDownClass() throws SQLException { // Delete inserted query con = ReferralManager.connect();/*from w w w . ja v a2 s . c om*/ PreparedStatement query = null; query = con.prepareStatement("DELETE FROM ShortURL WHERE custId= ? AND shortUrl = ?"); query.setLong(1, Long.parseLong((String) inviteData.get("custID"))); query.setString(2, shortURL); query.execute(); ReferralManager.disconnect(con, null); }
From source file:com.larasolution.serverlts.FileUploadHandler.java
private static void savetosql() { String columns;//from w w w.j av a2 s . c om String columnss = "model, avilableqty, reorderqty, minimusl, partCode"; columns = "Distributor_Code,Distributor_Name,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,Total_Value,Total_Qty"; columns = "Distributor_Code,Distributor_Name,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,Total_Value,Total_Qty"; String distAging = "disId, disName, 0to30, 31to60, 61to90, Over90days,@dummy"; try { String JDBC_DRIVER = "com.mysql.jdbc.Driver"; String myUrl = "jdbc:mysql://localhost/dashbord_ccl"; try { Class.forName(JDBC_DRIVER); } catch (Exception ex) { ex.printStackTrace(); } Connection conn = DriverManager.getConnection(myUrl, "lara", "lara@1234"); String query = "LOAD DATA LOCAL INFILE '" + CSV_FILE + "' INTO TABLE " + tablename + " FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE " + lines + " LINES (" + distAging + ") set id=null ;"; System.out.println(query); // create the mysql insert preparedstatement PreparedStatement psreparedStmt = conn.prepareStatement(query); // execute the preparedstatement psreparedStmt.execute(); } catch (SQLException ex) { ex.printStackTrace(); } }
From source file:com.chaosinmotion.securechat.server.commands.RemoveDevice.java
public static boolean processRequest(Login.UserInfo userinfo, JSONObject requestParams) throws ClassNotFoundException, SQLException, IOException { String deviceid = requestParams.optString("deviceid"); /*// w w w . ja v a 2 s. c o m * Delete device. We only delete if it is also ours. */ Connection c = null; PreparedStatement ps = null; ResultSet rs = null; try { c = Database.get(); ps = c.prepareStatement("DELETE FROM Devices " + "WHERE userid = ? AND deviceuuid = ?"); ps.setInt(1, userinfo.getUserID()); ps.setString(2, deviceid); ps.execute(); return true; } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } }
From source file:com.keybox.manage.db.ProfileDB.java
/** * deletes profile//from w ww . j a v a 2s .c o m * * @param profileId profile id */ public static void deleteProfile(Long profileId) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("delete from profiles where id=?"); stmt.setLong(1, profileId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } finally { DBUtils.closeConn(con); } }