A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
Passing Table Names in PreparedStatement
Joined: Oct 14, 2007
Apr 03, 2008 05:19:00
I was trying to pass a table name in the query dynamically like
query = "select * from ?";
pstmt = connection.prepareStatement(query);
It Throws an Exception
"Exception in thread "main" com.sybase.jdbc3.jdbc.SybSQLException: ASA Error -141: Table '@p0' not found"
Is there a way to pass the table name dynamically?
Thanks in Advance
Joined: Jul 28, 2003
Apr 03, 2008 06:22:00
We cannot pass tables as bind variable using prepared statement..
Instead form the query
eg: query="select * from "+var1;
Joined: May 18, 2007
Apr 03, 2008 06:35:00
Well we can't pass the tablename directly to prepared statements.
But, if you want to use stored procedures then you can pass table name dynamically using Dynamic SQL.
For further reading of Dynamic SQL refer
this article on Dynamic SQL
I agree. Here's the link:
subject: Passing Table Names in PreparedStatement
Hibernate createSQLQuery parameter substitution problem
In PreparedStatement table name can vary
html radio button add to database
execute Create table statement from JSP
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013