prepared-statement

How to prepare SQL statement with POINT using mysqli when using INSERT

本小妞迷上赌 提交于 2019-12-19 11:55:09
问题 I can't seem to find where documented to successfully prepare a statement that uses the POINT data type. This previous question (How to use POINT mysql type with mysqli - php) shows something marked as correct, but it doesn't work. I even tried using their simple query in their example: $stmt = $this->conn->prepare("INSERT INTO days(day,POINT(lat,lon)) VALUES(?,?,?)"); $stmt->bind_param("sdd", $day, $lat, $lon); This just simply returns and error: You have an error in your SQL syntax; check

MySql: Will using Prepared statements to call a stored procedure be any faster with .NET/Connector?

放肆的年华 提交于 2019-12-19 10:29:31
问题 I've been reading a bit about Prepared statements with MySql, and the .NET/Connector does support them. What I'm wondering, is if I use a prepared statement to call the same stored procedure thousands of times, is that any faster or better performance than not using prepared statements to do so (since the stored procedure should really be compiled already)? Eg: var mySqlCmd = new MySqlCommand(con, "call sp_someProcedure(@param1, @param2);"); mySqlCmd.Prepare(); mySqlCmd.Parameters

working with variable number of parameters in a preparedStatement

浪尽此生 提交于 2019-12-19 08:05:17
问题 I'm creating a search form for my application. In it user selects fields that should be used in filtering data. the number fields is variable so I don't know how many ? should be in where clause of SQL query. How can I use preparedStatement with variable number of conditions in where clause? Thanks 回答1: PrepardStatements don't support variable numbers of conditions. What some frameworks do, is they cache each PreparedStatement in a Map where the key is the query. So each time you want to run

batch preparedstatement with different sql queries

夙愿已清 提交于 2019-12-19 07:28:43
问题 I found existing questions similar to this one that did not actually have a clear answer to the question. A normal batch preparedstatement with one sql query would look something like this: private static void batchInsertRecordsIntoTable() throws SQLException { Connection dbConnection = null; PreparedStatement preparedStatement = null; String insertTableSQL = "INSERT INTO DBUSER" + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES" + "(?,?,?,?)"; try { dbConnection = getDBConnection();

How to insert Date into MySQL Database table in Java?

 ̄綄美尐妖づ 提交于 2019-12-19 05:07:26
问题 How do I insert date, without time, to MySQL database table? I tried these codes but I get the following exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Mar 05 00:00:00 GMT-08:00 2014,1,1)' at line 1 NOTE: In MySQL table, data type of this column I chose date datatype String Date = "\\d\\d\\d\\d\\D[0-1][0-9]\\D[0-3][0-9]"; while

Selecting rows where a field is null using PHP PDO prepared statements and MySQL

£可爱£侵袭症+ 提交于 2019-12-18 21:52:04
问题 I've been converting an app to use PDO prepared statements rather than mysqli and I'm running into a strange problem. I have some records in the database where it's expected that a field will be null. Not 'null' (string), or '' (empty string), but NULL. I build my queries dynamically, so in the past when I came across a null variable in an object, I'd build the query like this: WHERE fieldName is null; And would get the expected results when the field was null. Now with PDO, my queries aren't

Selecting rows where a field is null using PHP PDO prepared statements and MySQL

狂风中的少年 提交于 2019-12-18 21:50:30
问题 I've been converting an app to use PDO prepared statements rather than mysqli and I'm running into a strange problem. I have some records in the database where it's expected that a field will be null. Not 'null' (string), or '' (empty string), but NULL. I build my queries dynamically, so in the past when I came across a null variable in an object, I'd build the query like this: WHERE fieldName is null; And would get the expected results when the field was null. Now with PDO, my queries aren't

PDO positional and named parameters as part of the same prepared query?

非 Y 不嫁゛ 提交于 2019-12-18 19:37:57
问题 I'm learning the ropes with PDO. Here is my sql (the number of parameters that can appear in the WHERE is variable). SELECT ID, title FROM table WHERE something = ? ORDER BY :sort :dir LIMIT :start, :results Here is my code: $query = $conn->prepare($sql); if ($parameters) { $i = 0; foreach ($parameters AS $parameter) { $i++; $query->bindParam($i, $parameter); } } $query->bindParam(':start', $pagination['start'], PDO::PARAM_INT); $query->bindParam(':results', $pagination['results'], PDO::PARAM

How do I set a full date & time sql using java, and not just the date?

℡╲_俬逩灬. 提交于 2019-12-18 14:00:11
问题 I am trying to set a timestamp in my database using java, however in my table all I get is the date, and no time (i.e., looks like "2010-09-09 00:00:00"). I am using a datetime field on my mysql database (because it appears that datetime is more common than timestamp). My code to set the date looks like this: PreparedStatement ps = conn.prepareStatement("INSERT INTO mytable (datetime_field) VALUES (?)") java.util.Date today = new java.util.Date(); java.sql.Date timestamp = new java.sql.Date

Logging PreparedStatements in Java

社会主义新天地 提交于 2019-12-18 10:37:32
问题 One thing that always been a pain is to log SQL (JDBC) errors when you have a PreparedStatement instead of the query itself. You always end up with messages like: 2008-10-20 09:19:48,114 ERROR LoggingQueueConsumer-52 [Logger.error:168] Error executing SQL: [INSERT INTO private_rooms_bans (room_id, name, user_id, msisdn, nickname) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE room_id = ?, name = ?, user_id = ?, msisdn = ?, nickname = ?] Of course I could write a helper method for retrieving