prepared-statement

Java Prepared statement not executing

非 Y 不嫁゛ 提交于 2019-12-20 04:33:01
问题 I have created a small 3 tier program, consisting of : front end -> servlet -> database. Front end I enter some details into a form. They are passed to a servlet, which will render some HTML and display the values entered into the form, while also calling a class DatabaseHelper. The DatabaseHelper then connects and inserts these same values into a table. I know the values are being passed to the servlet class ok, as they are being displayed in the HTML. So the problem must lie within the

num_rows: get_result vs store_result

纵然是瞬间 提交于 2019-12-20 04:28:19
问题 The following code returns 0, even though there are 5 entries in the table categories with cat = 1 . $sql = "SELECT name FROM categories WHERE cat = ?"; $stmt = $db->prepare($sql); $cat = 1; $stmt->bind_param("i", $cat); $stmt->execute(); $stmt->get_result(); echo $stmt->num_rows; However, when I change $stmt->get_result(); to $stmt->store_result(); the output is 5 . Why does get_result() not work here? I found for instance on this answer: https://stackoverflow.com/a/8722329/2311074 that get

JDBC UPDATE With preparedStatement causing java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2) [duplicate]

浪子不回头ぞ 提交于 2019-12-20 03:51:18
问题 This question already has answers here : java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) [closed] (2 answers) Closed 3 years ago . I am facing java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2). while updating one or two columns of 'reset_info' table which has five columns (id, mobile_tower_id, reset_value, date_time, clientip). 'id' is auto-generated primary key. I want to UPDATE 'reset_value' of a particular

Use of LIKE clause in sql prepared statement, spring, SimpleJDBCTemplate

我只是一个虾纸丫 提交于 2019-12-20 02:57:07
问题 I have the following sql prepared statement: SELECT * FROM video WHERE video_name LIKE ? Im using spring and jdbc. i have a method, where term is a searchterm, sjt is a SimpleJdbcTemplate, VideoMapper is a RowMapper and searchForTermQuery is the string from above ... return sjt.query(searchForTermQuery, new VideoMapper(), term); My table has 2 videos that match the term. However when I run the query none is found. I get an empty List. I tried playing with % around the question mark, but it

PDO : Select using a prepared statement returns column name

时光毁灭记忆、已成空白 提交于 2019-12-20 02:31:28
问题 Hey guys, question if this is possible or not, maybe I'm not doing something right. I'm trying to use a prepared statement where the column is prepared i.e. SELECT ? FROM users Now this normally works if I put SELECT id FROM users But doing the first statement, the value is the column name. id = id 0 = 0 What am I doing wrong, or is this possible? Thanks 回答1: No you can't bind column names or table names. Here's more info Escaping column names in PDO statements 回答2: A prepared statement can

Why do I get this function call error on an non-object when I am calling a function on an object?

倖福魔咒の 提交于 2019-12-20 01:43:33
问题 Error: Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php on line 76 Code: public function countDaysWithoutEvents(){ $sql = "SELECT 7 - COUNT(*) AS NumDaysWithoutEvents FROM (SELECT d.date FROM cali_events e LEFT JOIN cali_dates d ON e.event_id = d.event_id WHERE YEARWEEK(d.date) = YEARWEEK(CURRENT_DATE()) AND c.category_id = ? GROUP BY DAY(d.date) ) AS UniqueDates"; $stmt = $this->link->prepare($sql); $stmt->bind_param('i', $this-

why does executeUpdate return 1 even if no new row has been inserted?

微笑、不失礼 提交于 2019-12-20 01:41:52
问题 here is my very simple table (Postgres): CREATE TABLE IF NOT EXISTS PERFORMANCE.TEST ( test text NOT NULL UNIQUE ); if I try to insert a String using the command below FROM the database,everything works as expected, not surprisingly a new row appears in the DB. insert into performance.test (test) values ('abbbbaw'); However if I want to insert a String through JDBC, nothing gets inserted, although preparedStatement.executeUpdate() always returns 1. Below is my method that should be working

PDO Error: “ Invalid parameter number: parameter was not defined”

若如初见. 提交于 2019-12-19 20:47:53
问题 I am trying to use a simple MySQL insert query with the parameters in array form. It keeps telling me the number of parameters are wrong. I have tried the following, all producing the same error: $stmt3 = $link->prepare('INSERT INTO messages VALUES(null, :room, :name, :message, :time, :color)'); $stmt3->execute(array(':room' => $Clean['room'],':name' => $Clean['name'],':message' => $Clean['message'],':time' => $time,':color:' => $Clean['color'])); and $stmt3 = $link->prepare('INSERT INTO

PHP PDO: how does re-preparing a statement affect performance

流过昼夜 提交于 2019-12-19 17:31:25
问题 I'm writing a semi-simple database wrapper class and want to have a fetching method which would operate automagically : it should prepare each different statement only the first time around and just bind and execute the query on successive calls. I guess the main question is: How does re-preparing the same MySql statement work, will PDO magically recognize the statement (so I don't have to) and cease the operation? If not , I'm planning to achieve do this by generating a unique key for each

Insert row into database with PreparedStatement

…衆ロ難τιáo~ 提交于 2019-12-19 12:24:50
问题 I want to insert a row into a table using PreparedStatement. The table got 3 columns(int, String, String). The thing is that the int column is AUTO_INCREMENT, so I want to leave that variable empty and let the database do that job (It's an id). Haven't found out how to do this though! It's an MySQL database. 回答1: That's relatively simple, just leave out the autoincrement column from the column list: insert into mytbl(str1, str2) values (?, ?) Prepare the statement, set the two parameters, and