• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CallableStatement calling stored procedure.

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm getting the following error -
"Unknown column 'std_int' in 'where clause"



Stored procedure -


EDIT : Fixed stored procedure parameter name
 
Tapas Chand
Ranch Hand
Posts: 583
8
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the definition of "students" table?
 
Tapas Chand
Ranch Hand
Posts: 583
8
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you intended to use "std_id" in the select query, but used "std_int" in place of that.
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a side note: SELECT * ought not be used outside of EXISTS() and add hoc queries. For actual code, it is much better to spell out the columns you want returned. This is self-documenting, and protects against issues related to column addition, renaming, or even column order switching.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Semwal wrote:I'm getting the following error -
"Unknown column 'std_int' in 'where clause"

As already mentioned by Tapas Chand, there seems to be a mismatch between the parameter name of the getidbelow procedure (std_id) and the column name in the query (std_int).

As a side note: if you are using a JDBC 4.0 compliant driver, you no longer need to explicitly load JDBC drivers using Class.forName(). The JDBC drivers are automatically loaded during initialitzation, thanks to the Java SE Service Provider mechanism (SPM). So you can remove line1 from your code snippet and the code will still work as intended.

Hope it helps!
Kind regards,
Roel
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tapas Chand wrote:Can you post the definition of "students" table?



FieldTypeNullKeyDefaultExtra
idint(11)NoPRINULLauto_increment
f_namevarchar(30)YES-NULL
l_namevarchar(30)YES-NULL
streamvarchar(20)YES-NULL


PS - It's very difficult to insert tables here.

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Tkatch wrote:On a side note: SELECT * ought not be used outside of EXISTS() and add hoc queries. For actual code, it is much better to spell out the columns you want returned. This is self-documenting, and protects against issues related to column addition, renaming, or even column order switching.


Good idea
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:As a side note: if you are using a JDBC 4.0 compliant driver, you no longer need to explicitly load JDBC drivers using Class.forName(). The JDBC drivers are automatically loaded during initialitzation, thanks to the Java SE Service Provider mechanism (SPM). So you can remove line1 from your code snippet and the code will still work as intended.


Its working.. I didn't knew that
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have 2 questions -
1: How do I display the returned results ?
2: Why am I calling the procedure inside {} ?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Semwal wrote:1: How do I display the returned results ?

I assume you are just using this stored procedure for demonstration (and learning) purposes only. Because if the stored procedure contains nothing but a SELECT statement, you should use a PreparedStatement instead of executing the query using a stored procedure.

If the stored procedure returns a ResultSet, you should use the following code to get the result set. Now you can easily loop through the returned result set and display the results

Shubham Semwal wrote:2: Why am I calling the procedure inside {} ?

Because that's the required syntax to call a stored procedure (using JDBC). More information about stored procedures can be found in this article of Oracle's JDBC tutorial.

Hope it helps!
Kind regards,
Roel
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay.. Thanks all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic