Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

exception is occurred. Please help.

 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a function written in UpdateDatabase.java class. When I am calling it. It is not returning the correct answer at all???
Here is the function



This function is called by following function call...



following is the database table:



if I use following statement the answer is returned:



after the call to database function it is always returning " ". It should return five1.
I do not know what is wrong with my code please help.
 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry forgot to post exception.
Here is the exception on a function call.

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the table variable "@P2".
 
Tim Cooke
Sheriff
Posts: 3447
163
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
waqas imtiaz wrote:SELECT ? "
+ "FROM ? "
+ "WHERE ? = ? ";

In a PreparedStatement you can only use ? as placeholders for data items in the "where" clause of your SQL statement. You cannot use ? as placeholders for column or table names.

You'll need to include the column and table name directly in your statement, for example:
 
waqas imtiaz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See I got it thanks.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!