prepared-statement

Java type in JDBC to Postgres ltree

我与影子孤独终老i 提交于 2019-12-12 07:20:54
问题 Does anyone know what Java type maps to a Postgres ltree type? I create a table like so: CREATE TABLE foo (text name, path ltree); A couple of inserts: INSERT INTO foo (name, path) VALUES ( 'Alice', 'ROOT.first.parent'); INSERT INTO foo (name, path) VALUES ( 'Bob', 'ROOT.second.parent'); INSERT INTO foo (name, path) VALUES ( 'Ted', 'ROOT.first.parent.child'); INSERT INTO foo (name, path) VALUES ( 'Carol', 'ROOT.second.parent.child'); Nothing strange there. Now I want to batch this up using a

Hive 2 JDBC PreparedStatement throws an error cannot recognize input near '?' '<EOF>' '<EOF>' in expression specification

梦想的初衷 提交于 2019-12-12 06:51:13
问题 try { Class.forName("org.apache.hive.jdbc.HiveDriver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(1); } String query = "SELECT spd_field_label_id FROM RAL WHERE SUBJECT_USER_ID = ?"; PreparedStatement stmt = null; Connection con = null; boolean testCasePassed = false; try { con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "", ""); stmt = con.prepareStatement(query); stmt.setString(1, "USR-44"); ResultSet

mysqli_stmt, arrays, & IN operator

梦想的初衷 提交于 2019-12-12 05:47:21
问题 I've looked all over, but I can't find any details on whether or not it's possible to easily and conveniently pass an array directly into the argument of the IN operator in a MySQL prepared statement. Most places suggest manually breaking up the array and building the statement, but there's got to be a better way. Is there? Many thanks in advance! EDIT Sorry, left out that this is for a prepared statement via mysqli_stmt not the traditional way. :( 回答1: Because IN operator takes values in

Syntax Error on using DECLARE and prepared statement inside CREATE PROCEDURE

醉酒当歌 提交于 2019-12-12 05:28:58
问题 I am trying to work with MySQL prepared statements inside of a stored procedure. I have been trying to debug this CREATE code for a couple of hours, now frustrated. DELIMITER // DROP PROCEDURE IF EXISTS doSomething// CREATE PROCEDURE doSomething(IN tblname CHAR(32)) BEGIN DECLARE str1 TEXT DEFAULT ''; SET str1 = CONCAT("SELECT * FROM ", tblname); PREPARE stmt1 FROM str1; EXECUTE stmt1; DEALLOCATE PREPARE stmt1; END// DELIMITER ; It is throwing up all sorts of "syntax" errors. Worse still, the

Binding a LIKE pattern value, two different approaches

别等时光非礼了梦想. 提交于 2019-12-12 05:17:26
问题 Is there any functional difference between these two approaches of binding a pattern for a LIKE clause via prepared statements? Constructing the pattern in the client: $stmt = $db->prepare('SELECT * FROM foo WHERE bar LIKE ?'); $stmt->bindValue(1, '%' . $searchTerm . '%'); Constructing the pattern within SQL: $stmt = $db->prepare("SELECT * FROM foo WHERE bar LIKE CONCAT('%', ?, '%')"); $stmt->bindValue(1, $searchTerm); This example uses PHP's PDO adapter, but this is not specific to PHP, PDO,

PHP Dynamic Prepared Statement - Number of Elements Not Matching [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:48:10
问题 This question already has answers here : Use one bind_param() with variable number of input vars (5 answers) Dynamically bind params in $bind_param(); Mysqli (2 answers) Closed 2 years ago . I am trying to construct a prepared statement dynamically and I keep getting the following error: mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables in When I echo my statements the number of type definitions matches the bind variable so I don't

When should I use prepared statements?

[亡魂溺海] 提交于 2019-12-12 04:45:09
问题 Originally I used mysql_connect and mysql_query to do things. Then I learned of SQL injection, so I am trying to learn how to use prepared statements. I understand how the prepare and execute functions of the PDO class are useful to prevent SQL injection. Are prepared statements only necessary when a users input is stored into a database? Would it be okay to still use mysql_num_rows , since I don't really run the risk of being hacked into by using this function? Or is it more secure to use

Single db connection that does not get initialised per task

丶灬走出姿态 提交于 2019-12-12 04:17:38
问题 public class Parser { ExecutorService pool = Executors.newFixedThreadPool(10); public void update() { Item item = new Item(subj.getName(), dateBuilder.toString(), cobBuilder.toString(), interest, count); pool.submit(new ItemDispatcher(item)); } } public class ItemDispatcher implements Runnable { private Item item; public ItemDispatcher(Item someItem) { this.item = someItem; } @Override public void run() { try { new Database(item).writeToDb(); } catch (SQLException e) { e.printStackTrace(); }

Writing a prepared statement to retrieve data from table (fatal error)

*爱你&永不变心* 提交于 2019-12-12 03:59:53
问题 I have a table called candidates with some fields. The table contains a column named "keypass" which is the same for all users and is set as default. Using prepared statement I'm trying to first capture the value for key pass (which is the same for this example) and compare it to the user input. the connection <?php $dbServerName = "localhost"; $dbUserName = "root"; $dbPassword = ""; $dbName = "candidateDB"; $conn = mysqli_connect($dbServerName,$dbUserName,$dbPassword,$dbName‌​); here is my

MySQL / Mariadb Stored Procedure, Prepared Statement, Union, Values from dynamically created tables and column names

淺唱寂寞╮ 提交于 2019-12-12 03:39:13
问题 I'd like to create reports without having to create a pivot table in excel for every report. I have survey software that creates a new table for each survey. The columns are named with ID numbers. So, I never know what the columns will be named. The software stores answers in two different tables depending on the 'type' of question. (text, radio button, etc.) I manually created a table 'survey_answers_lookup' that stores a few key fields but it duplicates the answers. The procedure 'survey