List of usage examples for java.sql ResultSet updateString
void updateString(String columnLabel, String x) throws SQLException;
String
value. From source file:Main.java
public static void main(String[] args) throws Exception { String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; Connection con;/*from w ww . ja va 2 s .com*/ Statement stmt; ResultSet uprs; try { Class.forName(driver); con = DriverManager.getConnection("jdbc:odbc:RainForestDSN", "student", "student"); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); uprs = stmt.executeQuery("SELECT * FROM Records"); // Check the column count ResultSetMetaData md = uprs.getMetaData(); System.out.println("Resultset has " + md.getColumnCount() + " cols."); int rowNum = uprs.getRow(); System.out.println("row1 " + rowNum); uprs.absolute(1); rowNum = uprs.getRow(); System.out.println("row2 " + rowNum); uprs.next(); uprs.moveToInsertRow(); uprs.updateInt(1, 150); uprs.updateString(2, "Madonna"); uprs.updateString(3, "Dummy"); uprs.updateString(4, "Jazz"); uprs.updateString(5, "Image"); uprs.updateInt(6, 5); uprs.updateDouble(7, 5); uprs.updateInt(8, 15); uprs.insertRow(); uprs.close(); stmt.close(); con.close(); } catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } }
From source file:InsertRowBug.java
public static void main(String args[]) { String url;/*from w w w . j a va 2 s . c o m*/ // url = "jdbc:odbc:SQL Anywhere 5.0 Sample"; // url = "jdbc:oracle:thin:@server:1521:db570"; url = "jdbc:odbc:RainForestDSN"; String driver; //driver = "oracle.jdbc.driver.OracleDriver"; driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String user, pass; user = "student"; pass = "student"; Connection con; Statement stmt; ResultSet uprs; try { Class.forName(driver); } catch (java.lang.ClassNotFoundException e) { System.err.println(e); return; } try { con = DriverManager.getConnection(url, user, pass); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); uprs = stmt.executeQuery("SELECT * FROM Music_Recordings"); // Check the column count ResultSetMetaData md = uprs.getMetaData(); System.out.println("Resultset has " + md.getColumnCount() + " cols."); int rowNum = uprs.getRow(); System.out.println("row1 " + rowNum); uprs.absolute(1); rowNum = uprs.getRow(); System.out.println("row2 " + rowNum); uprs.next(); uprs.moveToInsertRow(); uprs.updateInt(1, 150); uprs.updateString(2, "Madonna"); uprs.updateString(3, "Dummy"); uprs.updateString(4, "Jazz"); uprs.updateString(5, "Image"); uprs.updateInt(6, 5); uprs.updateDouble(7, 5); uprs.updateInt(8, 15); uprs.insertRow(); uprs.close(); stmt.close(); con.close(); } catch (SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); } }
From source file:org.biblionum.ouvrage.modele.CategorieOuvrageModele.java
/** * Java method that updates a row in the generated sql table * * @param con (open java.sql.Connection) * @param designation_categorie//from w ww.j ava2 s . co m * @return boolean (true on success) * @throws SQLException */ public static boolean updateCategorieouvrage(DataSource ds, int keyId, String designation_categorie) throws SQLException { con = ds.getConnection(); String sql = "SELECT * FROM categorieouvrage WHERE id = ?"; PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); statement.setInt(1, keyId); ResultSet entry = statement.executeQuery(); entry.last(); int rows = entry.getRow(); entry.beforeFirst(); if (rows == 0) { entry.close(); statement.close(); con.close(); return false; } entry.next(); if (designation_categorie != null) { entry.updateString("designation_categorie", designation_categorie); } entry.updateRow(); entry.close(); statement.close(); con.close(); return true; }
From source file:org.biblionum.commentaire.modele.CommentaireOuvragesModele.java
public static boolean updateOuvragetype(DataSource ds, int keyId, String contenu_commentaire, String date_commentaire, int utilisateurid, int ouvrageid) throws SQLException { Connection con = ds.getConnection(); String sql = "SELECT * FROM ouvragetype WHERE id = ?"; PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); statement.setInt(1, keyId);/* ww w . j a va 2s . c o m*/ ResultSet entry = statement.executeQuery(); entry.last(); int rows = entry.getRow(); entry.beforeFirst(); if (rows == 0) { entry.close(); statement.close(); con.close(); return false; } entry.next(); if (contenu_commentaire != null) { entry.updateString("contenu_commentaire", contenu_commentaire); } if (date_commentaire != null) { entry.updateString("date_commentaire", date_commentaire); } entry.updateInt("utilisateurid", utilisateurid); entry.updateInt("ouvrageid", ouvrageid); entry.updateRow(); entry.close(); statement.close(); con.close(); return true; }
From source file:oscar.util.JDBCUtil.java
private static ResultSet toResultSet(Node node, ResultSet rs) throws SQLException { int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { NamedNodeMap nnm = node.getAttributes(); String name = node.getNodeName(); String value = ""; Node next = node.getFirstChild(); if (next != null) { type = next.getNodeType();// ww w.j a va 2 s . c o m if (type == Node.TEXT_NODE) { value = next.getNodeValue(); } } if (!name.equalsIgnoreCase("Results") && !name.equalsIgnoreCase("Row") && !name.equalsIgnoreCase("ID")) rs.updateString(name, value); } //recurse for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { toResultSet(child, rs); } return rs; }
From source file:com.porvak.bracket.social.database.upgrade.v3.UpdateEncryptionMethod.java
License:asdf
@Override protected void doExecuteStatement(Statement statement) throws SQLException { ResultSet rs = statement.executeQuery("select apiKey, secret from App"); while (rs.next()) { rs.updateString("apiKey", encrypt(decrypt(rs.getString("apiKey")))); rs.updateString("secret", encrypt(decrypt(rs.getString("secret")))); rs.updateRow();/*from ww w . j a v a2s . co m*/ } rs = statement.executeQuery("select accessToken, secret from AppConnection"); while (rs.next()) { rs.updateString("accessToken", encrypt(decrypt(rs.getString("accessToken")))); rs.updateString("secret", encrypt(decrypt(rs.getString("secret")))); rs.updateRow(); } rs = statement.executeQuery("select member, provider, accessToken, secret from AccountConnection"); while (rs.next()) { rs.updateString("accessToken", encrypt(decrypt(rs.getString("accessToken")))); String secret = rs.getString("secret"); if (secret != null) { rs.updateString("secret", encrypt(decrypt(secret))); } rs.updateRow(); } }
From source file:org.opennms.model.utils.AssetsUpdater.java
protected static void parseCsv2(final File csv) throws ClassNotFoundException, SQLException, IOException { String sql = m_dbQuery;// w w w .j av a 2s . c o m Connection con = createConnection(false); PreparedStatement ps = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(csv))); CSVReader csvReader = new CSVReader(br); String[] line; int lineCnt = 0; while ((line = csvReader.readNext()) != null) { System.out.println("Processing csv line: " + String.valueOf(++lineCnt)); if (line.length != m_fieldMap.size() + 1) { continue; } String foreignSource = m_formatter.formatForeignSource(StringUtils.isBlank(line[0]) ? null : line[0]); System.out.println("Running query for foreignSource: " + foreignSource + " ..."); ps.setString(1, foreignSource); ResultSet rs = ps.executeQuery(); rs.last(); int rows = rs.getRow(); if (rows < 1) { rs.close(); System.out.println("No results found for foreignsource: " + foreignSource + "; continuing to next foreignsource..."); continue; } System.out.println("Found " + rows + " rows."); rs.beforeFirst(); while (rs.next()) { System.out.println("Updating node: " + rs.getInt("nodeid")); Set<Entry<Integer, String>> entrySet = m_fieldMap.entrySet(); for (Entry<Integer, String> entry : entrySet) { int csvField = entry.getKey() - 1; String columnName = entry.getValue(); System.out.println( "\t" + "updating column: " + columnName + " with csv field: " + line[csvField]); rs.updateString(columnName, line[csvField]); } rs.updateRow(); } rs.close(); } try { con.commit(); } catch (SQLException e) { e.printStackTrace(); con.rollback(); } csvReader.close(); ps.close(); con.close(); }
From source file:org.esupportail.dining.web.controllers.EditAdminController.java
@RequestMapping(params = { "action=setDefaultArea" }) public String setDefaultArea(@RequestParam(value = "chkArea[]", required = false) String[] listAreas) throws Exception { String areanames = ""; if (listAreas != null) { for (int i = 0; i < listAreas.length; i++) { areanames += listAreas[i] + (i < listAreas.length - 1 ? "," : ""); }// w w w. j ava 2 s . c o m } ResultSet results = this.dc.executeQuery("SELECT * FROM PATHFLUX"); results.next(); results.updateString("AREANAME", areanames); results.updateRow(); return "redirect:/admin/?areaSubmit=true"; }
From source file:net.solarnetwork.node.dao.jdbc.JdbcSettingDao.java
@Override protected void updateBatchRowEntity(BatchOptions options, ResultSet resultSet, int rowCount, Setting entity) throws SQLException { resultSet.updateString(1, entity.getKey()); resultSet.updateString(2, entity.getType()); resultSet.updateString(3, entity.getValue()); resultSet.updateInt(5, SettingFlag.maskForSet(entity.getFlags())); }
From source file:org.esupportail.dining.web.controllers.EditController.java
@RequestMapping(params = { "action=setUserArea" }) public String setUserArea(@RequestParam(value = "chkArea[]", required = false) String[] listAreas) throws Exception { User user = this.authenticator.getUser(); String areanames = ""; if (listAreas != null) { for (int i = 0; i < listAreas.length; i++) { areanames += listAreas[i] + (i < listAreas.length - 1 ? "," : ""); }//from w w w .j ava 2 s . com try { ResultSet results = this.dc .executeQuery("SELECT * FROM USERAREA WHERE USERNAME='" + user.getLogin() + "';"); results.next(); results.updateString("AREANAME", areanames); results.updateRow(); results.close(); } catch (SQLException e) { this.dc.executeUpdate("INSERT INTO USERAREA (USERNAME, AREANAME) VALUES ('" + StringEscapeUtils.escapeSql(user.getLogin()) + "', '" + StringEscapeUtils.escapeSql(areanames) + "');"); } return "redirect:/settings?zoneSubmit=true"; } return "redirect:/settings"; }