List of usage examples for java.sql PreparedStatement setString
void setString(int parameterIndex, String x) throws SQLException;
String
value. From source file:com.dynamobi.network.DynamoNetworkUdr.java
/** * Shows all available packages we have available. *///from w ww. ja v a 2 s .c om public static void showPackages(PreparedStatement resultInserter) throws SQLException { List<RepoInfo> repos = getRepoUrls(); for (RepoInfo inf : repos) { String repo = inf.url; if (!inf.accessible) { resultInserter.setString(1, repo); resultInserter.setBoolean(2, inf.accessible); resultInserter.executeUpdate(); continue; } JSONObject repo_data = downloadMetadata(repo); JSONArray pkgs = (JSONArray) repo_data.get("packages"); for (JSONObject obj : (List<JSONObject>) pkgs) { String jar = jarName(obj); String status = getStatus(jar); int c = 0; resultInserter.setString(++c, repo); resultInserter.setBoolean(++c, inf.accessible); resultInserter.setString(++c, obj.get("type").toString()); resultInserter.setString(++c, obj.get("publisher").toString()); resultInserter.setString(++c, obj.get("package").toString()); resultInserter.setString(++c, obj.get("version").toString()); resultInserter.setString(++c, jar); resultInserter.setString(++c, status); resultInserter.setString(++c, obj.get("depend").toString()); resultInserter.setString(++c, obj.get("rdepend").toString()); resultInserter.executeUpdate(); } } }
From source file:at.becast.youploader.database.SQLite.java
public static int saveTemplate(Template template) throws SQLException, IOException { PreparedStatement prest = null; ObjectMapper mapper = new ObjectMapper(); String sql = "INSERT INTO `templates` (`name`, `data`) " + "VALUES (?,?)"; prest = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); prest.setString(1, template.getName()); prest.setString(2, mapper.writeValueAsString(template)); prest.execute();//from w ww .j ava2 s . c o m ResultSet rs = prest.getGeneratedKeys(); prest.close(); if (rs.next()) { int id = rs.getInt(1); rs.close(); return id; } else { return -1; } }
From source file:at.becast.youploader.database.SQLite.java
public static void savePlaylists(Playlists playlists, int account) throws SQLException, IOException { PreparedStatement prest = null; String sql = "INSERT INTO `playlists` (`name`, `playlistid`,`image`,`account`) " + "VALUES (?,?,?,?)"; for (Playlists.Item i : playlists.items) { prest = c.prepareStatement(sql); prest.setString(1, i.snippet.title); prest.setString(2, i.id);/* ww w.java2 s .co m*/ URL url = new URL(i.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(3, imageBytes); prest.setInt(4, account); prest.execute(); prest.close(); } }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Update the login time of a user.//from ww w . j av a 2 s .c o m * @param userName the user name to update. * @param value the value of the login time, as a long integer. * @return true if the user's login time was updated successfully, false otherwise. */ public static boolean updateLoginTime(String userName, long value) { if (!MetaDbHelper.userExists(userName)) return false; Connection conn = Conn.initialize(); // Establish connection if (conn != null) { try { PreparedStatement updateUser = conn.prepareStatement(UPDATE_LAST_LOGIN); updateUser.setLong(1, value); updateUser.setString(2, userName); updateUser.executeUpdate(); updateUser.close(); conn.close(); // Close statement and connection return true; } catch (Exception e) { MetaDbHelper.logEvent(e); } } return false; }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
private static void addBindings(PreparedStatement stat, Resource subject, URI predicate, Value object) throws SQLException { int idx = 1;//from w w w .j a va2 s . c o m if (subject != null) stat.setString(idx++, subject.stringValue()); if (predicate != null) stat.setString(idx++, predicate.stringValue()); if (object != null) { stat.setString(idx++, object.stringValue()); stat.setString(idx++, object.stringValue()); if (object instanceof URI) stat.setBoolean(idx++, true); else { stat.setBoolean(idx++, false); stat.setString(idx++, getDataTypeAsString(object)); stat.setString(idx++, normalizeLang(((Literal) object).getLanguage())); } } }
From source file:fll.db.NonNumericNominees.java
/** * Add a set of nominees to the database. If the nominee already exsts, there * is no error./*from w ww . j a v a2s. c o m*/ * * @throws SQLException */ public static void addNominees(final Connection connection, final int tournamentId, final String category, final Set<Integer> teamNumbers) throws SQLException { PreparedStatement check = null; ResultSet checkResult = null; PreparedStatement insert = null; final boolean autoCommit = connection.getAutoCommit(); try { connection.setAutoCommit(false); check = connection.prepareStatement("SELECT team_number FROM non_numeric_nominees" // + " WHERE tournament = ?" // + " AND category = ?" // + " AND team_number = ?"); check.setInt(1, tournamentId); check.setString(2, category); insert = connection.prepareStatement("INSERT INTO non_numeric_nominees" // + " (tournament, category, team_number) VALUES(?, ?, ?)"); insert.setInt(1, tournamentId); insert.setString(2, category); for (final int teamNumber : teamNumbers) { check.setInt(3, teamNumber); insert.setInt(3, teamNumber); checkResult = check.executeQuery(); if (!checkResult.next()) { insert.executeUpdate(); } } connection.commit(); } finally { connection.setAutoCommit(autoCommit); SQLFunctions.close(checkResult); SQLFunctions.close(check); SQLFunctions.close(insert); } }
From source file:com.cisco.iwe.services.util.EmailMonitor.java
/** This method saves the email contents in the database **/ public static void saveAttachmentAndText(String from, String subject, byte[] mailAttachment, byte[] MailText, String fileType, Date sent, String pdfText) throws Exception { Connection conn = null;/* w w w . j av a 2 s .com*/ PreparedStatement stmt = null; try { String query = EmailParseConstants.saveQuery; conn = DataBaseUtil.getDevConnection(); // DataBaseUtil.getConnection(jndiName+"_"+System.getProperty("cisco.life")); conn.setAutoCommit(false); stmt = conn.prepareStatement(query); stmt.setString(1, from); stmt.setString(2, subject); stmt.setBinaryStream(3, new ByteArrayInputStream(mailAttachment), mailAttachment.length); stmt.setBinaryStream(4, new ByteArrayInputStream(MailText), MailText.length); stmt.setString(5, fileType); stmt.setTimestamp(6, new Timestamp(sent.getTime())); stmt.executeUpdate(); } finally { try { if (stmt != null) { } } finally { if (conn != null) { conn.close(); } } } }
From source file:com.keybox.manage.db.SystemDB.java
/** * inserts host system into DB// w ww. ja va 2 s . c om * * @param hostSystem host system object * @return user id */ public static Long insertSystem(HostSystem hostSystem) { Connection con = null; Long userId = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "insert into system (display_nm, user, host, port, authorized_keys, status_cd) values (?,?,?,?,?,?)", PreparedStatement.RETURN_GENERATED_KEYS); stmt.setString(1, hostSystem.getDisplayNm()); stmt.setString(2, hostSystem.getUser()); stmt.setString(3, hostSystem.getHost()); stmt.setInt(4, hostSystem.getPort()); stmt.setString(5, hostSystem.getAuthorizedKeys()); stmt.setString(6, hostSystem.getStatusCd()); stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { userId = rs.getLong(1); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return userId; }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Update the password of a user./*from w ww .j a v a 2s .c o m*/ * * @param userName The username of the user to update. * @param newPassword The new password for the user to update. * @return true if the user's password is updated successfully, false otherwise */ public static boolean updatePassword(String userName, String newPassword) { Connection conn = Conn.initialize(); // Establish connection if (conn != null) { try { PreparedStatement updateUser = conn.prepareStatement(UPDATE_USER_PASSWORD); newPassword = encryptPassword(newPassword); updateUser.setString(1, newPassword); updateUser.setString(2, userName); updateUser.executeUpdate(); updateUser.close(); conn.close(); // Close statement and connection return true; } catch (Exception e) { MetaDbHelper.logEvent(e); } } return false; }
From source file:com.asakusafw.bulkloader.testutil.UnitTestUtil.java
/** * ?????/*from ww w . j a v a2 s . com*/ * @param tableName * @return */ public static boolean isExistTable(String tableName) throws Exception { String url = ConfigurationLoader.getProperty(Constants.PROP_KEY_DB_URL); String schema = url.substring(url.lastIndexOf("/") + 1, url.length()); String sql = "SELECT count(*) as count FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=? AND TABLE_SCHEMA=?"; Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { printLog("executeQuery???SQL" + sql + "" + tableName + "," + schema, "isExistTable"); conn = DBConnection.getConnection(); stmt = conn.prepareStatement(sql); stmt.setString(1, tableName); stmt.setString(2, schema); rs = stmt.executeQuery(); if (rs.next()) { int count = rs.getInt("count"); if (count > 0) { printLog("??????" + tableName, "isExistTable"); return true; } else { printLog("??????" + tableName, "isExistTable"); return false; } } else { printLog("??????" + tableName, "isExistTable"); return false; } } finally { DBConnection.closeRs(rs); DBConnection.closePs(stmt); DBConnection.closeConn(conn); } }