Re: TYPE_FORWARD_ONLY
Posted in 2004
1) You need "EXECUTE PROCEDURE" instead of "CALL".
2) Remove brackets "{" and "}" from the quoted statement.
3) Use "?" as a place marker for variables.
4) Specify variables with "pstmt.setString(number,value)".
A full example follows.
Regards,
Doug Lawry
www.douglawry.webhop.org
-----------------------------------------------------------------
// Informix JDBC stored procedure demo
// Doug Lawry, 22/04/2004
import java.sql.*;
public class JdbcTest
{
static final String jdbc_url =
"jdbc:informix-sqli://" +
"YourHost/YourDatabase:" +
"INFORMIXSERVER=YourServer;" +
"user=YourLogin;" +
"password=YourPassword";
static final String sql_code =
"EXECUTE PROCEDURE YourProcedureName(?)";
static final String sql_data =
"YourProcedureParameterValue";
public static void main(String[] argv)
{
try
{
Class.forName("com.informix.jdbc.IfxDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("Unknown Class: " + e.getMessage());
return;
}
try
{
Connection conn = DriverManager.getConnection(jdbc_url);
PreparedStatement pstmt = conn.prepareStatement(sql_code);
pstmt.setString(1, sql_data);
ResultSet r = pstmt.executeQuery();
while (r.next())
System.out.println(r.getString(1));
}
catch(SQLException e)
{
System.out.println("SQL Exception: " + e.getMessage());
return;
}
}
}
-----------------------------------------------------------------
"Araujo" <araujo_guntin@hotmail.com> wrote:
Hi everybody...
I have the following stored procedure:
create procedure sp_select_tticu()
returning integer, char(50) ; define p_coditicu integer ;
define p_nombticu char(50);
foreach
select coditicu, nombticu
into p_coditicu, p_nombticu
from tticu
return p_coditicu, p_nombticu with resume ;
end foreach;
end procedure
..and I use it from JDBC, with following code:
public Object[][] select(String coditicu) {
valoresSeleccionados = coditicu;
PreparedStatement pstmt;
Object[][] selectCodiNomb = null;
try {
if (coditicu != null) {
pstmt = Connect.conn.prepareStatement(
"{call sp_coditicu(" + coditicu + ")};", ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY
);
}
else {
pstmt = Connect.conn.prepareStatement(
"{call sp_select_tticu()};");
}
ResultSet r = pstmt.executeQuery();
r.last();
int numberOfRecords = r.getRow();
selectCodiNomb = new String[numberOfRecords][2];
r.beforeFirst();
int i = 0;
while (r.next()) {
selectCodiNomb[i][0] = r.getString(1);
selectCodiNomb[i][1] = r.getString(2);
i++;
}
r.close();
pstmt.close();
return selectCodiNomb;
}
catch (SQLException e) {
System.out.println("FAILED: Prepare select(String coditicu) failed: "
+ e.getErrorCode());
}
return selectCodiNomb;
}
and I have the error:
FAILED: Prepare select(String coditicu) failed: -79767
because ResultSet Type is TYPE_FORWARD_ONLY, according to database messages.
What can I do????