Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: unable to view the result generated by stored procedure

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy unable to view the result generated by stored procedure

    Hi
    i have executing a stored procedure in which i have to give one input variable and the result will be a table view
    here is my stored procedure
    create proc getValues
    (
    @name varchar(50))
    as
    begin
    select PID,quantity,unitprice from productentry where product=@name
    end

    and the result is a view
    PID quantity unitprice
    1002 50 0.50

    how can i store each column with a variable and here is my javacode
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class sql 
    {
     public static void main(String args[])throws IOException,SQLException
    {  
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the Product name");
    String name=br.readLine(); 
    int pid;
    int q;
    Float price;
    Connection con=null;
    CallableStatement proc=null;
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:test","sa","haja");
    proc=con.prepareCall("{call getValues(?)}");
    proc.setString(1,name);
    proc.execute();
    pid=proc.getInt(1);
    q=proc.getInt(3);
    price=proc.getFloat(4);
    System.out.println(pid);
    System.out.println(q);
    System.out.println(price);
    }
    catch(ClassNotFoundException e)
            {
                System.out.println("couldnot load database driver"+e.getMessage());
            }
            catch(SQLException e)
            {
                System.out.println("sql exception caught"+e.getMessage());
            }
    }
    }
    whats wrong with my code

    help me
    Last edited by helloworld922; October 1st, 2010 at 05:35 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: unable to view the result generated by stored procedure

    A few things before we can help you, remember these on all your other posts:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code. This makes it easier for everyone to read your code.
    2. Explain to us what exactly your code is doing that is wrong. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly. This gives everyone an understanding of what the final product should be, compared to what you have now.

    Make those changes to your post, and do those on all your future posts, and you will receive help MUCH faster. Until those are done, I really can't help you much, as I don't have a full understanding to what is going on.

Similar Threads

  1. Is it possible to export Stored Procedures using JDBC?
    By sid7 in forum JDBC & Databases
    Replies: 0
    Last Post: August 28th, 2010, 05:34 PM
  2. How can i view search results by using servlet and jsp?
    By noFear in forum Java Theory & Questions
    Replies: 3
    Last Post: August 27th, 2010, 11:22 AM
  3. Value Not Being Stored
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 16th, 2010, 09:38 AM
  4. Executing Oracle Procedure
    By java_mein in forum JDBC & Databases
    Replies: 0
    Last Post: May 14th, 2010, 02:41 PM
  5. [SOLVED] installation procedure for java 1.6 latest version on xp
    By sriraj.kundan in forum Java Theory & Questions
    Replies: 1
    Last Post: June 25th, 2009, 08:18 AM