• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CallableStatement calling stored procedure.

 
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the definition of "students" table?
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 598
26
Oracle Notepad Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.. Thanks all
 
reply
    Bookmark Topic Watch Topic
  • New Topic