prepared-statement

Unable to Create Prepared Statements in MySQL

跟風遠走 提交于 2019-12-13 02:59:19
问题 I'm trying to create a prepared statement in MySQL that takes in a single parameter. When I try this on the command line I get a syntax error. However, when there are no variables in my prepared statement, I am able to create them fine. Below is a copy and paste of what I am seeing at the MySQL command prompt: mysql> PREPARE state_name FROM "select * from ? limit 1"; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for

Teradata: [Error 1154] [SQLState HY000] A failure occurred while inserting the batch of rows

不问归期 提交于 2019-12-13 02:35:38
问题 I have connected to my Teradata database via JDBC and am trying to use the FASTLOAD utility of Teradata to insert records into a table (with prepared statements and batch). Eg: connection = DriverManager.getConnection("jdbc:teradata://192.168.1.110/TYPE=FASTLOAD", "admin", "admin"); String sql = "INSERT INTO table (RANDOM_INTEGER) VALUES (?)"; PreparedStatement preparedStatement = connection.prepareStatement(sql); int numberOfRecordsToInsert = 100000; for (int i = 0; i <

mysql prepared statement java

对着背影说爱祢 提交于 2019-12-13 00:19:17
问题 I'm working with a prepared statement I've generated, and I'm getting a syntax error on the statement thrown by java. Yet when i copy and paste the toString of the PS into phpmyadmin for the database, it executes flawlessly. any idea's what could be wrong, i'm fairly stumped? edit: changed to ps.executeUpdate(query); still doesn't work. public int addOrder(Order order){ int rs=false; try { String query = "INSERT INTO `orders`(`orderNumber`, `productNumber`, `quantity`, `orderer`, `assembler`,

Any way to get the amount of rows returned using mysqli prepared statements?

狂风中的少年 提交于 2019-12-12 23:33:21
问题 Wondering if there is a way to get the amount of rows returned from a query using mysqli prepared statements, sort of like mysql_num_rows($query); 回答1: Presuming you're doing something like: $result = $statement->execute(); You can get the number of rows with $result->num_rows; See the manual. 回答2: Use this code: $result = $mysqli->query($query); $num_rows = $result->num_rows($result); 来源: https://stackoverflow.com/questions/4607487/any-way-to-get-the-amount-of-rows-returned-using-mysqli

How to use PreparedStatement and Case INsensitive search

帅比萌擦擦* 提交于 2019-12-12 23:24:47
问题 1.How do I use PrepareStatement for familyname and givenname? 2.Also, how do I case insensitive search by familyname or givenname? String query ="SELECT agent.familyname, agent.givenname" + " FROM agent" + " WHERE agent.agentid = piececreation.agentid" + " AND (LOWER(familyname) = '"+agent_lastname+"' OR LOWER(givenname) = '"+agent_name+"') ORDER by familyname"; PreparedStatement pst = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); pst.setString(1, agent_lastname); pst

vs2012: SQLite: Access violation reading location 0x0000000C

做~自己de王妃 提交于 2019-12-12 21:24:23
问题 I am implementing SQLite Prepare-Statement in vs2012 using C. I am using this link as a tutorial to capture the processes that are running in my machine every time I run my code. Everything is working fine except that the prepare-statement does not allow me to put it outside the do-while loop. if I put it inside the do-while loop then I am doing nothing actually because with every db-insertion the prepare-statement is again executed which is not practical. however, when I put the prepare

See query with arguments in Go database/sql package

a 夏天 提交于 2019-12-12 21:09:17
问题 I'm trying to test the behavior of passing arguments to the sql.DB.Query method (using the database/sql package, and the PostgreSQL driver at github.com/lib/pq). Is there any way to get the raw query string after it's been processed to see how the arguments were inserted? I was thinking, for example, of writing a prepared query and then inspecting the resulting statement. Any ideas? Thanks! 回答1: It doesn't look like it inserts parameters in the query itself. It sends the query, then waits for

Wrapping a prepared statement in a function

非 Y 不嫁゛ 提交于 2019-12-12 20:59:01
问题 I've been reading articles about SQL Injection, and decided to modify my code to prevent SQL injection. For example, I have an input which I insert the value to my database. Initially, my guard against injection was this: function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); // $data = addslashes($data); $data = mysql_real_escape_string($data); return $data; } $artist = $_POST["artist"]; // can be anything $artist = test_input($artist)

SqlServer PrepareStatement set parameters for SQL 'in(?)' clause

心已入冬 提交于 2019-12-12 19:42:43
问题 I have a sql which looks like this: SELECT * FROM T_TABLE WHERE ID IN(?) I wanna to set parameters for IN(?) via PrepareStatement . I think the desired method would looked like this: prepareStatement.setList(1,Arrays.asList("1","2","3")); But I don't know which method should I use to achieve this. I have tried setArray method with the help from here and I got these error messages. java.sql.SQLFeatureNotSupportedException: at com.microsoft.sqlserver.jdbc.SQLServerConnection.createArrayOf

preparedStatement SQL Error

社会主义新天地 提交于 2019-12-12 19:17:52
问题 Here is my code: public int checklogin(String email, String key){ int res = -1; try { String selectSQL = "SELECT id FROM table WHERE email = ? AND key = ?"; PreparedStatement preparedStatement = dbConnection.prepareStatement(selectSQL); preparedStatement.setString(1, email); preparedStatement.setString(2, key); ResultSet rs = preparedStatement.executeQuery(); if (rs.next()) res = rs.getInt("id"); rs.close(); preparedStatement.close(); } catch (Exception e) { e.printStackTrace(); } return res;