prepared-statement

“ORA-01008: not all variables bound” error

耗尽温柔 提交于 2019-11-29 13:14:57
I am using following method for calculating payroll by using jdbc but "ORA-01008: not all variables bound" error is not removing. Any idea please? I am using following code public double getPayroll(){ ResultSet rs = null; ResultSet rs1 = null; ResultSet rs2 = null; Connection conn = null; PreparedStatement pstmt = null; try { conn = getDBConnection(); double dailyPay=0,basicPay=0,payroll2=0; int houseRent=0,convAllow=0,noOfPresents=0,empId=0; String q = "select e_id from employee"; pstmt = conn.prepareStatement(q); rs = pstmt.executeQuery(); while (rs.next()) { empId=rs.getInt(1); String q1 =

MySQLi dynamic prepared function with array binding

二次信任 提交于 2019-11-29 12:27:00
I am attempting to create a database query function which can take multiple parameters and be reused elsewhere, however tried a number of methods online similar to my approach and they are not working as expected. function query($query, $bindings, $type) I want to be able to run queries on the go with this single function, this type of function is a lot easier with the PDO driver as you could simply enter the binding inside ->execute($binding); however in this case I am forced to use MySQLi as the application currrently relies on it but wanting to upgrade it to use prepared statements. An

Preventing SQL injection without prepared statements (JDBC)

落花浮王杯 提交于 2019-11-29 11:38:28
I have a database log appender that inserts a variable number of log lines into the database every once in a while. I'd like to create an SQL statement in a way that prevents SQL injection, but not using server-side prepared statements (because I have a variable number of rows in every select, caching them won't help but might hurt performance here). I also like the convenience of prepared statments, and prefer them to string concatination. Is there something like a 'client side prepared statement' ? It sounds like you haven't benchmarked the simplest solution - prepared statements. You say

Prepared statement cannot be executed multiple times with integer values

这一生的挚爱 提交于 2019-11-29 10:59:38
How do I properly re-execute a prepared statement using different integer values? There's something deathly wrong with explicit and implicit binding PDO::PARAM_INT when reusing an ODBC prepared statement. CREATE TABLE mytab ( col INT, something VARCHAR(20) ); Works : multiple strings $pdoDB = new PDO('odbc:Driver=ODBC Driver 13 for SQL Server; Server='.DATABASE_SERVER.'; Database='.DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD ); $pdoDB->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $values = ['here','are','some','values']; $sql = "INSERT INTO mytab (something) VALUES (

How to upgrade from mysql_* to mysqli_*?

筅森魡賤 提交于 2019-11-29 10:55:18
I'm currently using deprecated code to get data from users, as follows: /* retrieve */ $lastName = $_POST['lastName']; $firstName = $_POST['firstName']; $examLevel=$_POST['level']; /* connect */ $dbc=mysql_connect("localhost", "user", "passw") or die('Error connecting to MySQL server'); mysql_select_db("db") or die('Error selecting database.'); /* sanitize */ $lastName=mysql_real_escape_string($lastName); $firstName=mysql_real_escape_string($firstName); $examLevel=mysql_real_escape_string($examLevel); /* insert */ $query_personal = "INSERT INTO personal (LastName, FirstName) VALUES ('$lastName

How to use MySQL prepared statement caching?

情到浓时终转凉″ 提交于 2019-11-29 10:14:12
How do i take advantage of MySQL's ability to cache prepared statements? One reason to use prepared statements is that there is no need to send the prepared statement itself multiple times if the same prepared statement is to be used again. Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mydb" + "?cachePrepStmts=true", "user", "pass"); for (int i = 0; i < 5; i++) { PreparedStatement ps = conn.prepareStatement("select * from MYTABLE where id=?"); ps.setInt(1, 1); ps.execute(); } conn.close() When running the above Java example I

How to use bind_result() instead of get_result() in php

♀尐吖头ヾ 提交于 2019-11-29 07:55:29
I'm working on a project for uni and have been using the following code on a testing server to get all devices from a table based on a user_id : public function getAllDevices($user_id) { $stmt = $this->conn->prepare("SELECT * FROM devices WHERE primary_owner_id = ?"); $stmt->bind_param("i", $user_id); $stmt->execute(); $devices = $stmt->get_result(); $stmt->close(); return $devices; } This worked fine on my testing server but returns this error when migrating over to the university project server: Call to undefined method mysqli_stmt::get_result() Some googling suggests using bind_result()

MySQLI Prepared Statement: num_rows & fetch_assoc

会有一股神秘感。 提交于 2019-11-29 07:27:13
Below is some poorly written and heavily misunderstood PHP code with no error checking. To be honest, I'm struggling a little getting my head around the maze of PHP->MySQLi functions! Could someone please provide an example of how one would use prepared statements to collect results in an associative array whilst also getting a row count from $stmt? The code below is what I'm playing around with. I think the bit that's throwing me off is using $stmt values after store_result and then trying to collect an assoc array, and I'm not too sure why... $mysqli = mysqli_connect($config['host'], $config

Why does SQLite give a “database is locked” for a second query in a transaction when using Perl's DBD::SQLite?

余生颓废 提交于 2019-11-29 07:23:06
Is there a known problem with SQLite giving a "database is locked" error for a second query in a single transaction when using Perl DBD::SQLite? Scenario: Linux, Perl DBI, AutoCommit => 0, a subroutine with two code blocks (using the blocks to localize variable names). In the first code block a query handle is created by prepare() on a select statement, it is executed() and the block closed. The second code block another query handle is created by prepare for an update statement, and frequently (30% of the time) SQLite/DBI gives a database locked error at this stage. I think the error happens

How to use prepared statement in JPA

五迷三道 提交于 2019-11-29 06:56:16
I am a play framework application Developer.I am using createNativeQuery method in JPA. In this example i want to use prepared statement. Please anyone help me? Here is the code without JPA. I need help to convert it to Prepared statement. Query query = JPA.em().createNativeQuery("select count(*) from truck t inner join" + "box b where t.truck_id=b.truck_id and t.shipment_upc='" + code + "'"); BigInteger val = (BigInteger)query.getSingleResult(); System.out.println(val); Query query = JPA.em().createNativeQuery("select count(*) from truck t inner join box b where t.truck_id=b.truck_id and t