Hi, I'm trying to pass variables to a table in SQL 7.0 using the following statement: stmt.execute("insert into table_name values(i,j)"); //Assume that all variables and objects are declared correctly. This works fine when I send numbers like 100 or 5. But I get the follwing run-time exception when trying to execute the above statement: Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]The name 'i' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted. Please advise. Thank you. Ahmed.
Ahmed Haboubi
Ranch Hand
Joined: Oct 21, 2000
Posts: 36
posted
0
OK, I got it !! The statement should be concatenated with the variables like this: stmt.executeUpdate("insert into table1 values("+ i + "," + j + ")"); Now it's working Ahmed.
I agree with Dave. Just wait until you start inserting values like "O'Meara" into the database. You'll wished you used a preparedStatement then! There is no performance difference in using a Statement over a PreparedStatement when executing a single query(based on tests that I have done from creation to execution). But if you can reuse a PreparedStatement, there is significant performance gain over a Statement. And as I eluded to earlier, PreparedStatements deal with special characters for you. Go PreparedStatements! Jamie
Ahmed Haboubi
Ranch Hand
Joined: Oct 21, 2000
Posts: 36
posted
0
Excuse my ignorance guys, but what's a PreparedStatement and how can I use it?? I've never programmed an application that uses JDBC.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.