prepared-statement

Supply a prepared statement with an array

浪尽此生 提交于 2019-12-24 10:18:02
问题 Can I use a prepared statement in Postgres to add multiple values? When I saw that things are added to the prepared statement with array($val) , it sort of occurred to me that I should be able to supply an array of values to be put in my table. Is this wildly incorrect? When I tried, I saw in my db table only Array . I don't know if it is an actual array, but I'm guessing, just the word, as the column is a simple character variable . $tag = array('item1', 'item2', 'item3'); // Prepare a query

With mysqli and prepared statements can I PASS IN COLUMN NAMES to 'ORDER BY'

百般思念 提交于 2019-12-24 10:02:22
问题 I need to be able to use prepared MYSQLI statements for security reasons. I need to be able to ORDER BY COLUMNNAME DIRECTION However, the COLUMNNAME is DYNAMIC as is the DIRECTION (ASC/DESC) When I bind mysqli parameters I get 'COLUMNNAME' 'ASC' or 'COLUMNNAME' 'DESC' Whereas what I need is NO QUOTES........ Is there anyway to do this? I have seen someone ask something similar in Are PHP MySQLi prepared queries with bound parameters secure? 回答1: It is not possible to use parameter binding for

Java MySQL PreparedStatement SELECT Statement [closed]

空扰寡人 提交于 2019-12-24 09:49:47
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have a database and a Java Program. I am trying to write a code, so that if in a textfield a MockID is entered, and the submit button is pressed, the

how to insert variable into a table in MySQL

放肆的年华 提交于 2019-12-24 09:48:17
问题 I know how to add data into a table. Like String insertQuery = "INSERT INTO tablename (x_coord, y_coord)" +"VALUES" +"(11.1,12.1)"; s.execute(insertQuery); 11.1 and 12.1 can be inserted into table. Now given a float variable float fv = 11.1; how to insert fv into the table? 回答1: In JAVA, you can use prepared statements like this: Connection conn = null; PreparedStatement pstmt = null; float floatValue1 = 11.1; float floatValue2 = 12.1; try { conn = getConnection(); String insertQuery =

Binding NULL in JAVA for MySQL PreparedStatment?

醉酒当歌 提交于 2019-12-24 09:25:33
问题 MySQL uses "IS NULL" instead of "NULL" so how do i bind variable to achieve the same ? Right now i tried with this selectStmt.setNull( 2, java.sql.Types.VARCHAR ); when i printed "java.sql.Types.VARCHAR" shows value = 12 ? If so how does this set " IS NULL" in preparedstatment ? MORE DETAILS: i.e I am interested in querying (MySQL) for null if i have string = " " in input. So logic goes like this, Connection c = SQLCon.connect(); PreparedStatement selectStmt = c.prepareStatement( "select *

Throw an exception in a function or how to do descent error handling [closed]

↘锁芯ラ 提交于 2019-12-24 09:09:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am currently using MySQLi prepared statements for my database handling. Because MySQLi prepared statements only throw an error when the connection is wrong, I am forced to check for errors myself and to throw them myself too. In PDO (which I am going to use in the future because I'm convinced now it works way

How do I call java.sql.Connection::abort?

被刻印的时光 ゝ 提交于 2019-12-24 08:52:44
问题 I would like to write a SwingWorker that, when the user cancels the task, it: 1) cancels the PreparedStatement and 2) aborts the Connection . Here is some code to illustrate: class Task extends SwingWorker<Void, Void> { Connection conn; PreparedStatement p_stmt; @Override protected Void doInBackground() throws Exception { ResultSet results = p_stmt.executeQuery(); while(results.next()) { if(isCancelled()) return; } return null; } void cancell() { cancel(true); try { p_stmt.cancel(); conn

pdo prepared statement multiple execution?

余生长醉 提交于 2019-12-24 08:22:41
问题 I'm just getting to implement PDO in my site but I was wondering if it is possible to execute prepared statement multiple times? $SQL = $dbh->prepare("SELECT * FROM user WHERE id=? AND users=?"); $SQL -> execute(array($id,$userid)); while($check = $SQL -> fetchObject()){ and then I would use a while loop for this SQL Can I use the same $SQL for another execution within the while loop? So I don't have to type in the prepared statement again? $SQL -> execute(array($id2,$userid2)); while($check2

How to pass table name to a Prepared Statement in a SELECT COUNT query? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-24 07:27:39
问题 This question already has answers here : Is it possible to supply parameters for table or column name in Prepared Statements or QueryRunner.update()? (1 answer) Using Prepared Statements to set Table Name (7 answers) How to use a tablename variable for a java prepared statement insert [duplicate] (5 answers) Closed 2 years ago . So I have this following method which works just fine: static void getCount(final String url, final String username, final String password) throws SQLException {

PostgreSQL performance of ad-hoc SQL vs functions

给你一囗甜甜゛ 提交于 2019-12-24 06:29:28
问题 Is there any difference? I know SQL queries are having their execution plans cached just as good as functions. I foud someone telling: Performance is an issue, and we suspect query planning might be an underlying cause. I've rewritten the scripts from ad-hoc SQL to a Postgres functions (CREATE FUNCTION) and we saw server load go down quite a bit. But why? 回答1: The query plan for ad-hoc queries is not cached, only for prepared statements. And PL/pgSQL functions handle all SQL statements like