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:hu.bme.mit.trainbenchmark.benchmark.sqlite.driver.SQLiteDriver.java
@Override public void read(final String modelPath) throws IOException, InterruptedException, SQLException { final File modelFile = new File(modelPath); if (!modelFile.exists()) { throw new IOException("Model does not exist: " + modelPath); }// w w w . j av a 2 s . com connection = DriverManager.getConnection("jdbc:sqlite::memory:"); final Statement statement = connection.createStatement(); statement.setQueryTimeout(3600); final String sql = FileUtils.readFileToString(new File(modelPath)); statement.executeUpdate(sql); // create temporary table (used by the transformations) final PreparedStatement createStatement = connection .prepareStatement("CREATE TEMP TABLE IF NOT EXISTS Variables (Name TEXT PRIMARY KEY, Value LONG);"); createStatement.execute(); }
From source file:mvc.dao.TarefaDAO.java
public boolean finalizarTarefa(Long id) { String sql = " update tarefas set finalizado=true, " + " dataFinalizacao=now() where id = ? "; try {/*from ww w. j av a 2s . c om*/ PreparedStatement stmt = connection.prepareStatement(sql); stmt.setLong(1, id); stmt.execute(); } catch (SQLException e) { throw new RuntimeException(e); } return true; }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void updateAuthenticateData(String msisdn, String status) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update `authenticated_login` set " + "status=? where " + "msisdn=?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, status);//from w w w . ja v a2s.c om ps.setString(2, msisdn); log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } }
From source file:net.mindengine.oculus.frontend.db.jdbc.MySimpleJdbcDaoSupport.java
public Long queryForLong(String sql) throws Exception { logQuery(sql, null);/*from www . ja v a 2s.c o m*/ PreparedStatement ps = getConnection().prepareStatement(sql); ps.execute(); ResultSet rs = ps.getResultSet(); if (rs.next()) { return rs.getLong(1); } return null; }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void updateMultiplePasswordNoOfAttempts(String username, int attempts) throws SQLException, AuthenticatorException { Connection connection = null; PreparedStatement ps = null; String sql = "update `multiplepasswords` set attempts=? where username=?;"; connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setInt(1, attempts);/* ww w .j a v a2s . c o m*/ ps.setString(2, username); log.info(ps.toString()); ps.execute(); if (connection != null) { connection.close(); } }
From source file:controllers.ConfigurationController.java
@RequestMapping(value = "ps_execute", produces = "application/json; charset=utf-8") public @ResponseBody String executeSqlQuery(@RequestParam(value = "query") String query) { Session session = SessionProvider.openSession(); try {// w ww. j a v a 2 s . c o m PreparedStatement ps = session.getActiveConnection().prepareStatement(query); ps.execute(); session.commit(); ps.close(); session.close(); return new OperationResult(StatusRetorno.OPERACAO_OK, "", "").toJson(); } catch (Exception ex) { ex.printStackTrace(); session.close(); return new OperationResult(StatusRetorno.FALHA_INTERNA, "Ocorreu um problema durante a criao do banco de dados. Acione o suporte Doware.", "") .toJson(); } }
From source file:FacultyAdvisement.StudentRepository.java
public static void create(DataSource ds, Student student) throws SQLException { String studentSQL = "INSERT INTO STUDENT(STUID, EMAIL, FIRSTNAME, LASTNAME, MAJORCODE, PHONE, ADVISED) " + "VALUES (?, ?, ?, ?, ?, ?, \'false\')"; String userSQL = "INSERT INTO USERTABLE(PASSWORD, USERNAME, VERIFIED) VALUES (?, ?, ?)"; //haseeb was here String groupSQL = "INSERT INTO GROUPTABLE(GROUPNAME, USERNAME) VALUES (\'customergroup\', ?)"; if (ds == null) { throw new SQLException("ds is null; Can't get data source"); }//from w w w .j a v a 2 s . c om Connection conn = ds.getConnection(); if (conn == null) { throw new SQLException("conn is null; Can't get db connection"); } try { //Here we execute three SQL statements //Student Information PreparedStatement sqlStatement = conn.prepareStatement(studentSQL); sqlStatement.setString(1, student.getId()); sqlStatement.setString(2, student.getUsername()); sqlStatement.setString(3, student.getFirstName()); sqlStatement.setString(4, student.getLastName()); sqlStatement.setString(5, student.getMajorCode()); sqlStatement.setString(6, student.getPhoneNumber()); sqlStatement.executeUpdate(); //user credentials sqlStatement = conn.prepareStatement(userSQL); //Encrypt the pssword into SHA-256 sqlStatement.setString(1, SHA256Encrypt.encrypt(student.getPassword())); sqlStatement.setString(2, student.getUsername()); sqlStatement.setString(3, "false"); sqlStatement.execute(); //Group Table sqlStatement = conn.prepareStatement(groupSQL); sqlStatement.setString(1, student.getUsername()); sqlStatement.execute(); } finally { conn.close(); } }
From source file:dk.statsbiblioteket.doms.licensemodule.persistence.H2Storage.java
public static void shutdown() { log.info("Shutdown H2Storage"); try {//w w w . j av a 2 s . co m if (singleDBConnection != null) { PreparedStatement shutdown = singleDBConnection.prepareStatement("SHUTDOWN"); shutdown.execute(); if (singleDBConnection != null) { singleDBConnection.close(); } Thread.sleep(3000L); } } catch (Exception e) { // ignore errors during shutdown, we cant do anything about it anyway log.error("shutdown failed", e); } }
From source file:dao.MaterialDaoImplem.java
@Override public boolean deleteMaterial(Material material) { try (Connection connection = dataSource.getConnection()) { String query = ("delete from material where id_material=?"); PreparedStatement stat = connection.prepareStatement(query); stat.setInt(1, material.getId_material()); stat.execute(); return true; } catch (Exception e) { throw new RuntimeException("Error:deleteMaterial", e); }/*from w ww. ja v a 2 s.c om*/ }
From source file:fr.gael.dhus.database.liquibase.ExtractProductDatesAndDownloadSize.java
@Override public void execute(Database database) throws CustomChangeException { // contentStart contentEnd ingestionDate download.size JdbcConnection databaseConnection = (JdbcConnection) database.getConnection(); try {//w w w .java 2s . c o m // SELECT PRODUCT_ID, QUERYABLE, VALUE FROM METADA_INDEXES PreparedStatement getQueryables = databaseConnection .prepareStatement("SELECT PRODUCT_ID, QUERYABLE, VALUE " + "FROM METADATA_INDEXES"); ResultSet res = getQueryables.executeQuery(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); while (res.next()) { Long productIdentifier = (Long) res.getObject("PRODUCT_ID"); String queryable = (String) res.getObject("QUERYABLE"); String value = (String) res.getObject("VALUE"); String query = ""; if ("beginPosition".equals(queryable)) { Date d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(value); query = "UPDATE PRODUCTS SET CONTENTSTART = '" + sdf.format(d) + "' WHERE ID = " + productIdentifier; } else if ("endPosition".equals(queryable)) { Date d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(value); query = "UPDATE PRODUCTS SET CONTENTEND = '" + sdf.format(d) + "' WHERE ID = " + productIdentifier; } else if ("ingestionDate".equals(queryable)) { Date d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(value); query = "UPDATE PRODUCTS SET INGESTIONDATE = '" + sdf.format(d) + "' WHERE ID = " + productIdentifier; } else { continue; } PreparedStatement updateProduct = databaseConnection.prepareStatement(query); updateProduct.execute(); updateProduct.close(); } getQueryables.close(); } catch (Exception e) { LOGGER.error("Error during liquibase update " + "'ExtractProductDatesAndDownloadSize'", e); } try { PreparedStatement getQueryables = databaseConnection .prepareStatement("SELECT p.ID, p.DOWNLOAD_PATH FROM PRODUCTS p "); ResultSet res = getQueryables.executeQuery(); while (res.next()) { Long productIdentifier = (Long) res.getObject("ID"); String path = (String) res.getObject("DOWNLOAD_PATH"); File dl = new File(path); if (dl.exists()) { PreparedStatement updateProduct = databaseConnection .prepareStatement("UPDATE PRODUCTS SET DOWNLOAD_SIZE = " + dl.length() + " WHERE ID = " + productIdentifier); updateProduct.execute(); updateProduct.close(); } } getQueryables.close(); } catch (Exception e) { LOGGER.error("Error during liquibase update " + "'ExtractProductDatesAndDownloadSize'", e); } }