prepared-statement

Return number of rows affected by SQL UPDATE statement in Java

混江龙づ霸主 提交于 2019-11-29 05:25:57
I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement("UPDATE user_table SET Level = 'Super' WHERE Username = ?"); prep1.setString(1, username); The update statement above works fine however I'd like to get the number of rows affected with this statement. Is this possible please? Calling executeUpdate() on your PreparedStatement should return an int, the number of updated records. Statement.executeUpdate() or execute() followed by getUpdateCount() will return the number of rows matched , not updated , according to the JDBC spec. If

Using PreparedStatement pooling in dbcp

时光总嘲笑我的痴心妄想 提交于 2019-11-29 04:38:12
Can someone explain how exactly prepared connection pooling using dbcp can be used? (with some example code if possible). I've figured out how to turn it on - passing a KeyedObjectPoolFactory to the PoolableConnectionFactory. But how should the specific prepared statements be defined after that? Right now I'm only using a PoolingDataSource to get connections from the pool. How do I use the prepared statements from the pool? Well talking about getting connection from the pool vs getting "not-pooled" connection, do you have any change in your code :)? I bet you do not. Same way with prepared

SQLite: bind list of values to “WHERE col IN ( :PRM )”

一曲冷凌霜 提交于 2019-11-29 02:52:28
all I want to do is send a query like SELECT * FROM table WHERE col IN (110, 130, 90); So I prepared the following statement SELECT * FROM table WHERE col IN (:LST); Then I use sqlite_bind_text(stmt, 1, "110, 130, 90", -1, SQLITE_STATIC); Unfortunately this becomes SELECT * FROM table WHERE col IN ('110, 130, 90'); and is useless (note the two additional single quotes). I already tried putting extra ' in the string but they get escaped. I didn't find an option to turn off the escaping or prevent the text from being enclosed by single quotes. The last thing I can think of is not using a

What's the difference between the mysqli functions bind_result, store_result and fetch?

醉酒当歌 提交于 2019-11-29 02:44:24
问题 I'm running into problems knowing when and what to call after mysqli_stmt_execute How do you know when to call mysqli_stmt_bind_result mysqli_stmt_store_result mysqli_stmt_fetch 回答1: mysqli_stmt_bind_result() tells mysqli which variable you want to be populate when you fetch a row, but it doesn't fetch() anything yet. This is necessary to call once, before you call fetch. mysqli_stmt_store_result() sets an optional behavior so that the client downloads all rows when you fetch() the first row,

Why even use *DB.exec() or prepared statements in Golang?

我的未来我决定 提交于 2019-11-29 02:23:51
I'm using golang with Postgresql. It says here that for operations that do not return rows (insert, delete, update) we should use exec() If a function name includes Query, it is designed to ask a question of the database, and will return a set of rows, even if it’s empty. Statements that don’t return rows should not use Query functions; they should use Exec(). Then it says here : Go creates prepared statements for you under the covers. A simple db.Query(sql, param1, param2), for example, works by preparing the sql, then executing it with the parameters and finally closing the statement. If

PDO in Codeigniter - Protect vs SQL Injection

断了今生、忘了曾经 提交于 2019-11-29 02:05:47
True PHP Security experts, is PDO the way to go or would I be ok with Codeigniter's Active Record class? I have read http://codeigniter.com/forums/viewthread/179618/ and am not 100% convinced. I usually lean on experts such as Chris Shiflett and OWASP for security tips. http://shiflett.org/blog/2006/jul/the-owasp-php-top-5 Been using a homebrewed PDO DB Class in place of the Codeigniter Database files. Everytime I upload it is a relatively small pain to copy over. The main reason I use PDO is to protect from SQL Injection vs using Active Record. EDIT: NOT TO BE A SHILL but I wrote a post after

Which should I close first, the PreparedStatement or the Connection?

点点圈 提交于 2019-11-29 01:50:36
问题 When using a PreparedStatement in JDBC, should I close the PreparedStatement first or the Connection first? I just saw a code sample in which the Connection is closed first, but it seems to me more logical to close the PreparedStatement first. Is there a standard, accepted way to do this? Does it matter? Does closing the Connection also cause the PreparedStatement to be closed, since the PreparedStatement is directly related to the Connection object? 回答1: The statement. I would expect you to

Java JDBC - Multiple prepared statement bulk insert

回眸只為那壹抹淺笑 提交于 2019-11-28 23:30:53
Using JDBC (Oracle) I need to insert about thousand rows into each of two tables. Something like this: "INSERT INTO TABLE_A (A_ID, A_NAME, A_LAST_NAME) VALUES (MY_SEQUENCE.NEXTVAL, ?, ?)"; "INSERT INTO TABLE_B (B_ID, B_DESCRIPTION) VALUES (MY_SEQUENCE.CURRVAL, ?)"; The problem is that both tables are connected through common sequence, so that order of statements is important. It would be quite easy if I had only one table. In that case I used code: String insert = "Insert into TABLE_A(A_ID, A_NAME, A_LAST_NAME) values(MY_SEQUENCE.NEXTVAL, ?, ?)"; conn.setAutoCommit(false); PreparedStatement ps

$stmt->close() vs $stmt->free_result()

我们两清 提交于 2019-11-28 22:36:21
问题 I am trying to clarify the difference between $stmt->close() and $stmt->free_result() when finalizing a prepared mysqli statement. So far I use: $mysqli = new mysqli(host,user,password,database); $stmt = $mysqli->prepare(sql statement); [...] $stmt->free_result(); $mysqli->close(); and everything seems to work fine. But I've seen a lot of programmers use $stmt->close instead of $stmt->free_result(). And once I've seen both of them: $stmt->free_result(); $stmt->close(); $mysqli->close(); So

What does it mean when I say Prepared statement is pre-compiled?

你说的曾经没有我的故事 提交于 2019-11-28 21:33:49
I am using MySQL in Java . I don't have a good understanding of PreparedStatement . I know it is better to use PreparedStatement than Statement . The reason being it is compiled. What do we mean by compiled? M Sach When you use prepared statement(i.e pre-compiled statement), As soon as DB gets this statement, it compiles it and caches it so that it can use the last compiled statement for successive call of same statement. So it becomes pre-compiled for successive calls. You generally use prepared statement with bind variables where you provide the variables at run time. Now what happens for