prepared-statement

SQL 1064 Syntax Error using a JDBC prepared statement

孤者浪人 提交于 2019-12-02 05:32:50
问题 I have: String query = "INSERT INTO Basestations VALUES(?, ?, ?, ?, ?, ?, ?," + "?, ?, ?, ?, ?, ?, ?, ?)"; PreparedStatement prep = conn.prepareStatement(query); prep.setInt(1, profile.getNetworkId()); prep.setInt(2, profile.getBaseStationId()); prep.setInt(8, profile.getLoadLevel()); prep.setInt(11, profile.getPositionX()); prep.setInt(12, profile.getPositionY()); prep.setInt(13, profile.getPort()); prep.setDouble(3, profile.getSignalStrength()); prep.setDouble(4, profile.getFrequency());

PostgreSQL syntax error in parameterized query on “date $1”

半城伤御伤魂 提交于 2019-12-02 05:14:09
Trying to parameterize my SQL queries (using libpq function PQexecParams ), I was stuck on a syntax error: SELECT date $1 The error is: ERROR: syntax error at or near "$1" Prepared statements The explanation for this can be found in the chapter Constants of Other Types of the manual : The :: , CAST() , and function-call syntaxes can also be used to specify run-time type conversions of arbitrary expressions, as discussed in Section 4.2.9 . To avoid syntactic ambiguity, the type 'string' syntax can only be used to specify the type of a simple literal constant. Another restriction on the type

Assigning the same parameter value multiple times in pdo execute

十年热恋 提交于 2019-12-02 05:05:26
I originally had an SQL statement, this: SELECT *, COUNT(friend_one) AS pending_count , COUNT(friend_two) AS requests_sent FROM friends WHERE friend_one OR friend_two = ? AND status = ? In which I assigned my parameters like : $pending_friend_count_stmt->execute(array($user_id, $status_one)); However, the query was not getting the results I wanted. Someone showed me a different way of doing it, but it has the variable $user_id in it multiple times, so I do not know how to adjust the code to be able to use a parameter. You can see the new query here: http://rextester.com/KSM73595 Am I able to

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

核能气质少年 提交于 2019-12-02 04:29:49
This question already has an answer here: java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) [closed] 2 answers 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 row Now Following is the source code: Class.forName("com.mysql.jdbc.Driver"); System.out.println("Connecting to database...");

Get the query plan using jdbc PreparedStatement on sql server

扶醉桌前 提交于 2019-12-02 04:16:19
Using Statment, resultSet.getObject returns query plan as xml Connection conn = getConnection(); String query = " SET SHOWPLAN_XML on "; Statement st = conn.createStatement(); boolean execute=st.execute(query); log.info("execute status {} " , execute); query = " SELECT ATMPROFILES.TERMID as COLUMNID, ATMPROFILES.TERMID as COLUMNNAME FROM ATMPROFILES (NOLOCK) " + " WHERE Authprocessname = 'ATMST' " + "ORDER BY ATMPROFILES.TERMID "; ResultSet rs = st.executeQuery(query); while(rs.next()) { Object object = rs.getObject(1); log.info("Query Plan {} ", object); } But If I execute the same through

php binding dynamic number of variables for batch insert query

我是研究僧i 提交于 2019-12-02 03:52:34
问题 I have a web service where a user passes up a dynamic number of questions. On the php side I am using explode with the ? to strip out each question. I then need to do a batch insert. What I've done so far is as follows: $checkInQs = explode("?", trim($_POST['checkInQs'], "?")); $checkInSql = "INSERT INTO CheckListQs (ID, GeofenceID, type, question) VALUES "; $checkInInsertQuery = array(); $checkInInsertData = array(); foreach($checkInQs as $q){ $checkInInsertQuery[] = "('',?, 1, ?)";

condition for creating a prepared statement using cfqueryparam?

有些话、适合烂在心里 提交于 2019-12-02 03:46:05
问题 Does cfquery becomes a prepared statement as long as there's 1 cfqueryparam ? Or are there other conditions? What happen when the ORDER BY clause or FROM clause is dynamic? Would every unique combination becomes a prepared statement? And what happen when we're doing cfloop with INSERT , with every value cfqueryparam'ed, and invoke the cfquery with different number of iterations? Any potential problems with too many prepared statements? How does DB handle prepared statement? Will they be

Java MySQL preparedStatement Batch

自作多情 提交于 2019-12-02 03:28:59
I am trying to use the preparedStatement Batch but I am having a problem. The following code does not give me errors, but it inserts in the table only last key of the map and I do not know why. It will be surely a very stupid error, but this is the first time I use the addBatch() method.. Class.forName("com.mysql.jdbc.Driver"); this.connect = DriverManager.getConnection("jdbc:mysql://localhost/" + this.database + "?user=" + this.user + "&password=" + this.password); String s; for (String key : this.map.keySet()) { s = ("insert into " + this.database + ".user (nickname) values (?)"); this

Alternative to using Prepared Statement in Trigger with MySQL

拥有回忆 提交于 2019-12-02 03:28:25
I'm trying to create a MySQL Before Insert trigger with the following code which would do what I want it to do if I could find a way to execute the prepared statement generated by the trigger. Are the any alternative ways to execute prepared statements from within triggers? Thanks BEGIN SET @CrntRcrd = (SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='core_Test'); SET @PrevRcrd = @CrntRcrd-1; IF (NEW.ID IS NULL) THEN SET NEW.ID = @CrntRcrd; END IF; SET @PrevHash = (SELECT Hash FROM core_Test WHERE Record=@PrevRcrd); SET @ClmNms = (SELECT CONCAT

Problem with multiple prepared statements

牧云@^-^@ 提交于 2019-12-02 03:01:12
Here's the issue. I have a prepared statement, like this: $select_something = $db->stmt_init(); $select_something->prepare (" SELECT whatever FROM table "); $select_something->execute(); $select_something->bind_result($whatever); When alone - it works. When I add another one after it's execution it also works. But when I try to just first prepare them both: $select_something = $db->stmt_init(); $select_something->prepare (" SELECT whatever FROM table "); and execute them later on: $select_something->execute(); $select_something->bind_result($whatever); the first statement gets executed, and