× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I'm trying to learn Java and as a byproduct i'm learning about Stored
Procedures also.  I have a small java program that i'm trying to convert
the data base functions to Stored procedures.  I have a couple of
questions.   First, i'll list my first Stored procedure that i created
via STRSQL. 

create procedure SPgetInv (IN Item CHAR(5))                         
result sets 1 language sql begin                                    
declare itemid char(5);                                             
declare at_end int default 0;                                       
 declare                                                            
c1 cursor with return for select * from Inventory where itemid =    
item; open c1;                                                      
 end        

here is the code where i call the procedure. 
public static Inventory findInventory(String itemID) {
if(!isConnected)
{
connect();
isConnected=true;
}
String stored = "{call " + "SPGETINV(?)" + "}";
PreparedStatement pstmt;
String query = " Select * from inventory where itemId = ?";
Inventory Inv =null;
try
{
pstmt = aConnection.prepareCall(stored);
pstmt.setString(1,itemID); 
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
// Create the next client object, and load the fields.
Inv = new Inventory();
Inv.setItemId(rs.getString("itemId") );
Inv.setItemName(rs.getString("itemName") );
Inv.setShortDesc(rs.getString("shortDesc"));
Inv.setLongDesc(rs.getString("longDesc"));
Inv.setPrice(rs.getFloat("price") );
Inv.setPricePerd(rs.getString("pricePerD") );
Inv.setImageUrl(rs.getString("imageUrl") );
Inv.setCategory(rs.getString("category") );
Inv.setOnHand(rs.getInt("onHand") );
} 
Inventory retval = Inv;
pstmt.close();
return retval;
}
catch(SQLException ex)
{
System.out.println("Exception in DBRoutines.findInventory
method...Insert into orders ");
System.out.println(ex);
return null;
}


Now, the first time i call this procedure it works fine, but when it
gets called a second time, i get a 'cursor already open' message.
Where/How do i close the cursor.  Do i create a seperate procedure, do i
include it in this procedure?    

Secondly, since i'm only going to be selecting 1 record at any time from
the Inventory file, i suspect i should be creating a cursor(i know i
wouldn't if i were doing embedded sql in an rpg program).  How would i
create this procedure to select only 1 record.      

Any other tips,suggestions welcome.

Thanks 

Mike                                                    


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.