prepared-statement

PreparedStatement won't ever timeout even if explicitly set

Deadly 提交于 2020-01-13 05:08:06
问题 I am trying to simulate an scenario where my service loses connection to a database and cannot do an INSERT by blocking the connection with iptables, but I can't make the executeQuery() method to timeout. What I did is setting a timeout for the PreparedStatement like this statement.setQueryTimeout(5) . Here is the code. HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:mysql://db-url/db"); config.setUsername("user"); config.setPassword("passwd"); config.setMaximumPoolSize(10);

How to set positional/named parameters dynamically to JPA criteria query?

荒凉一梦 提交于 2020-01-12 14:50:33
问题 Hibernate provider does not generate prepared statement for non-string type parameters unless they are set to entityManager.createQuery(criteriaQuery).setParameter(Parameter p, T t); as done by EclipseLink, by default. What is the way to set such parameters, if they are supplied dynamically at run time. For example, CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<Long>criteriaQuery=criteriaBuilder.createQuery(Long.class); Metamodel metamodel=entityManager

How to set positional/named parameters dynamically to JPA criteria query?

梦想的初衷 提交于 2020-01-12 14:48:17
问题 Hibernate provider does not generate prepared statement for non-string type parameters unless they are set to entityManager.createQuery(criteriaQuery).setParameter(Parameter p, T t); as done by EclipseLink, by default. What is the way to set such parameters, if they are supplied dynamically at run time. For example, CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<Long>criteriaQuery=criteriaBuilder.createQuery(Long.class); Metamodel metamodel=entityManager

How to debug SQLSTATE[HY000]: General error: 2031 in prepared statements

泪湿孤枕 提交于 2020-01-11 13:12:30
问题 I have this prepared statement query $stmt = $conn->prepare(" UPDATE language SET lang_alias=:lang_alias , lang_name=:lang_name WHERE lang_id=:lang_id" ); If I set an array to bind the values $query_array = array ( ":lang_alias" => "en", ":lang_name" => "English (UK)", ":lang_id" => 1 ) ; and then execute it $stmt->execute(array($query_array)); it wont work, I get Notice: Array to string conversion referring to $stmt->execute(array($query_array)); and Uncaught exception 'PDOException' with

Go sql - prepared statement scope

孤人 提交于 2020-01-11 12:21:52
问题 I'm building an API using the Go (1.6.x) sql package along with with PostGres (9.4). Should my prepared statements have application or request scope? Having read the docs it would seem more efficient to scope them at the application level to reduce the number of preparation phases. However, perhaps there are other considerations and prepared statements are not designed to live that long? 回答1: Prepared statements are so that you can execute repetitive SQL commands which may only differ in

Go sql - prepared statement scope

夙愿已清 提交于 2020-01-11 12:21:26
问题 I'm building an API using the Go (1.6.x) sql package along with with PostGres (9.4). Should my prepared statements have application or request scope? Having read the docs it would seem more efficient to scope them at the application level to reduce the number of preparation phases. However, perhaps there are other considerations and prepared statements are not designed to live that long? 回答1: Prepared statements are so that you can execute repetitive SQL commands which may only differ in

Mysqli prepared statement fetch_assoc

牧云@^-^@ 提交于 2020-01-11 11:25:07
问题 I've tried over and over to figure out why this code isn't working, I have several rows in this table but when I try to execute this it is not returning the rows, everything else is working including the first prepared statement, I have tried using this code in other places and it works just fine, I can also bind the result to a variable and echo the info from the variable so it is there, I have no idea why it won't echo the rows, any advice appreciated! <?php include_once 'includes/functions

how to implement like operator in prepared statement? [duplicate]

╄→гoц情女王★ 提交于 2020-01-11 10:44:24
问题 This question already has an answer here : Use of LIKE clause in sql prepared statement, spring, SimpleJDBCTemplate (1 answer) Closed 3 years ago . ps=con.prepareStatement("select * from REGISTER inner join ORGAN on REGISTER.PATIENTID=ORGAN.PATIENTID where ORGAN.ORGAN LIKE ?"); ps.setString(1,"'%"+o.getOrgan()+"%'"); I executed the query in SQL Developer which works fine, but in DAO class it is not returning any result set. 回答1: Use ps.setString(1, "%" + o.getOrgan() + "%"); Note the absence

PHP prepared statements - check if a value already exists

左心房为你撑大大i 提交于 2020-01-11 07:29:32
问题 I am trying to do a check on a value (email), to determine if it already exist in the db. This should be done using prepared statements. What is the best way for doing this? My solution is this (which is wrong): $mysqli = connectToDB(); $getEmail = $mysqli->prepare('SELECT * FROM users WHERE email=?') or die('Couldn\'t check the email'); $getEmail->bind_param('s', $email); $getEmail->execute(); $countRows = $getEmail->num_rows; print $countRows; It always prints out 0 even though the email

MYSQLi bind_result is returning null

你说的曾经没有我的故事 提交于 2020-01-10 05:34:26
问题 I am trying to output the variables that I get from the database in my query but nothing is being returned. Using MYSQLi prepared statements. Please see code below: $stmt = $con->prepare("SELECT first_name, last_name FROM transactions WHERE order_id = ?"); $stmt->bind_param('i', $order_id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($first_name, $last_name); $stmt->close(); // Output review live to page echo $first_name; I cannot see where I am going wrong? PS I am new to