Calling Stored Procedure in SDK Code
Hello Experts,
Iam facing a problem in Sdk Code...How do i Excute the stored procedure in sdkcode.I have aStored Procedure ,In My Stored Procedures (My Operation Is DML operation Insert),Inserting UDO (Document Data) To the Normal Table.
I am Having Data in Matrix and when Add the Document I am calling the Procedure.How Do establish Connection and How do i Use the Commands to excute the Procedure and Save to the Normal Table..
Dim sqlconn As New SqlConnection("Data Source=" & SBO_Company.Server & ";Database=" & SBO_Company.CompanyDB & "; User ID=" & SBO_Company.DbUserName & ";Password=sap;")
Dim sqldaa As New SqlDataAdapter
Dim dss As New DataSet
If sqlconn.State = ConnectionState.Closed Then
sqlconn.Open()
End If
Dim sqlcmdd As New SqlCommand("PRODSALETOALL", sqlconn)
sqlcmdd.CommandType = CommandType.StoredProcedure
'sqlcmd.CommandText = "PRODSALE"
sqlcmdd.Parameters.Add("@fy", "bb")
sqlcmdd.Parameters.Add("@doctype", "aa")
'sqldaa.SelectCommand = sqlcmdd
'sqldaa.Fill(dss)
'sqldaa.Dispose()
sqlcmdd.ExecuteNonQuery()
sqlcmdd.Dispose()
Help would be Appreciated..
Regards,
Kumar
Haroon,
SAP does not allow Stored Procedures to be used as part of the SAP Business Db or to be used to access SAP Business One tables directly for Insert, Update or Delete. Any interaction with the SAP Business One Db is required to go through the SAP Business One API's, namely the DI and UI API's.
Eddy
Similar Messages
-
Need sample source code for calling stored procedure in Oracle
Hi.
I try to call stored procedure in oracle using JCA JDBC.
Anybody have sample source code for that ?
Regards, Arnold.Thank you very much for a very quick reply. It worked, but I have an extended problem for which I would like to have a solution. Thank you very much in advance for your help. The problem is described below.
I have the Procedure defined as below in the SFCS1 package body
Procedure Company_Selection(O_Cursor IN OUT T_Cursor)
BEGIN
Open O_Cursor FOR
SELECT CompanyId, CompanyName
FROM Company
WHERE CompanyProvince IN ('AL','AK');
END Company_Selection;
In the Oracle Forms, I have a datablock based on the above stored procedure. When I execute the form and from the menu if I click on Execute Query the data block gets filled up with data (The datablock is configured to display 10 items as a tabular form).
At this point in time, I want to automate the process of displaying the data, hence I created a button and from there I want to call this stored procedure. So, in the button trigger I have the following statements
DECLARE
A SFCS1.T_Cursor;
BEGIN
SFCS1.Company_Selection(A);
go_Block ('Block36');
The cursor goes to the corresponding block, but does not display any data. Can you tell me how to get the data displayed. In the future versions, I'm planning to put variables in the WHERE clause. -
Call stored procedure with OUT parameter
Hello,
I have created a short-lived process. Within this process I am using the "FOUNDATION > JDBC > Call Stored Procedure" operation to call an Oracle procedure. This procedure has 3 parameters, 2 IN and 1 OUT parameter.
The procedure is being executed correctly. Both IN parameters receive the correct values but I am unable to get the OUT parameter's value in my process.
Rewriting the procedure as a function gives me an ORA-01460 since one of the parameters contains XML (>32K) so this is not option...
Has someone been able to call a stored procedure with an OUT parameter?
Regards,
NicoObject is Foundation, Execute Script
This is for a query, you can change to a stored procedure call. Pull the value back in the Java code then put into the process variable.
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.*;
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:IDP_DS");
conn = ds.getConnection();
stmt = conn.prepareStatement("select FUBAR from TB_PT_FUBAR where PROCESS_INSTANCE_ID=?");
stmt.setLong(1, patExecContext.getProcessDataLongValue("/process_data/@inputID"));
rs = stmt.executeQuery();
rs.next();
patExecContext.setProcessDataStringValue("/process_data/outData", rs.getString(1));
} finally {
try {
rs.close();
} catch (Exception rse) {}
try {
stmt.close();
} catch (Exception sse) {}
try {
conn.close();
} catch (Exception cse) {} -
Calling Stored Procedure without JDBC-Adapter
Hallo,
as it is not possible calling Stored Procedures with the parameter Typ Record in Oracle my question: It is possible connecting to DB using native java-code for example in Mapping?
Thanks in advance,
FrankHi Frank,
Maybe you can use the DB look up using the JDBC adapter in your mapping.
Just check this blog for the same,
/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
As for calling an Oracle Strored Procedure, it is possible using a RECEIVER JDBC adapter, but not a SENDER JDBC adapter.
<i> import the jdbc-driver (oracle) in an archive in Designer.</i>
Also, this imported archive should be under any Namespace, but, it should be in the same SWCV as the one in which the mapping is being executed.
Regards,
Bhavesh -
Calling stored procedure in OCCI
Hi, Guys.
I triy to call stored procedure in Oracle database server.But i have problems with taking of the OUT parameters.
How to call the procedure corectly?
Depend on Oracle manual everything is fine but as we see that is not.
Here is the 2 lines that make the problem.
statement->registerOutParam(2, Type::OCCIINT, sizeof ( if_false ) );
statement->registerOutParam(3, Type::OCCIString, sizeof ( __result ) );
I can't access Type::OCCIINT and Type::OCCIString.
I tried and Type::OCCISTRING but without any result.
Can you help me?
This is the all code i use:
Environment *env = Environment::createEnvironment ( Environment::DEFAULT );
Connection *conn = env->createConnection ( user, pass, osid );
Statement * statement = conn->createStatement ( query );
ResultSet * result = statement->executeQuery ( query );
result->setCharacterStreamMode ( 2, 10000 );
statement->setSQL ( "BEGIN tracetst.get_tst_moduls ( :1, :2, :3 ); END:" );
int if_false;
string __result;
statement->setString ( 1, "116714020010" );
statement->registerOutParam(2, Type::OCCIINT, sizeof ( if_false ) );
statement->registerOutParam(3, Type::OCCIString, sizeof ( __result ) );
statement->executeUpdate();
if_false = statement->getInt (2);
/* Set the 1,2 args into err_result and modules. The action is only with these */
err_result = if_false;
__result = statement->getString (3);
cout << if_false;
cout << __result;
//printf ( result );
//statement->executeUpdate ( query );
env->terminateConnection ( conn );
Environment :: terminateEnvironment ( env );
While compiling I have an error message.Here it is :
trace.cpp: In member function `const char* oracle_io::get_data()':
trace.cpp:668: error: `oracle::occi::Type' is not an aggregate type
Tha is the line adn the next line is same :
statement->registerOutParam(2, Type::OCCIINT, sizeof ( if_false ) );
statement->registerOutParam(3, Type::OCCIString, sizeof ( __result ) );
How to call the procedure corectly?
Depend on Oracle manual everything is fine but as we see that is not.
Thanks in advance.
P.S. I would like to thanks to Amogh for helping me before.Did you remove the colon after END ?
Environment *env = Environment::createEnvironment(Environment::OBJECT);
Connection *conn = env->createConnection("scott","tiger","inst1");
Statement *stmt;
int num; string name;
try
stmt=conn->createStatement();
stmt->setSQL ( "BEGIN scott.test ( :1, :2, :3 ); END;" );
stmt->setString ( 1, "11" );
stmt->registerOutParam(2, OCCIINT,sizeof(num));
stmt->registerOutParam(3, OCCISTRING,sizeof(name));
stmt->execute();
num=stmt->getInt(2); name=stmt->getString(3);
cout<<num<<" "<<name<<endl;
catch (SQLException &ex)
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
cout<<ex.getMessage();
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
...Rgds.
Amogh -
How to call stored procedure in hibernate
hi ,
can any one help me how to call stored procedure in hibernate.Given code in hbm.xml
and also plz tell me what is the use of <return-property/>in given hbm.xml file.
<sql-query name="selectEmployees_SP" callable="true">
<return alias="emp" class="com.centris.Employee">
<return-property name="eno" column="eno"/>
<return-property name="ename" column="ename"/>
<return-property name="address" column="address"/>
<return-property name="salary" column="salary"/>
{ ? = call p_retrieve_employees() }
</return>
</sql-query>Hi,
Your question isn't related to Java Programming and should be asked in a [Hibernate forum|http://forum.hibernate.org/]
Kaj -
How to use @jws:sql call Stored Procedure from Workshop
Is there anyone know how to use @jws tag call Sybase stored procedure within
Workshop,
Thanks,Anurag,
Do you know is there any plan to add this feature in future release? and
when?
Thanks,
David
"Anurag Pareek" <[email protected]> wrote in message
news:[email protected]..
David,
In the current release, we do not support calling stored procedures from a
database control. You will have to write JDBC code in the JWS file to call
stored procedures.
Regards,
Anurag
Workshop Support
"David Yuan" <[email protected]> wrote in message
news:[email protected]..
Anurag,
I know how to use DB connection pool and create a db control with it. In
fact, we have created a Web Service with the db control using plain SQL
in
@jws:sql. However, my question here is how to use @jws tag in Weblogic
Workshop to create a Web Services based on Sybase stored procedure orany
Stored Proc not plain SQL.
Thanks,
David
"Anurag Pareek" <[email protected]> wrote in message
news:[email protected]..
David,
You can use a database control to obtain a connection from any JDBC
Connection Pool configured in the config.xml file. The JDBC Connectionpool
could be connecting to any database, the database control is
independent
of
that.
Regards,
Anurag
Workshop Support
"David Yuan" <[email protected]> wrote in message
news:[email protected]..
Is there anyone know how to use @jws tag call Sybase stored
procedure
within
Workshop,
Thanks, -
How to call stored procedure with multiple parameters in an HTML expression
Hi, Guys:
Can you show me an example to call stored procedure with multiple parameters in an HTML expression? I need to rewrite a procedure to display multiple pictures of one person stored in database by clicking button.
The orginal HTML expression is :
<img src="#OWNER#.dl_sor_image?p_offender_id=#OFFENDER_ID#" width="75" height="75">which calls a procedure as:
procedure dl_sor_image (p_offender_id IN NUMBER)now I rewrite it as:
PROCEDURE Sor_Display_Current_Image(p_n_Offender_id IN NUMBER, p_n_image_Count in number)could anyone tell me the format for the html expression to pass multiple parameters?
Thanks a lot.
SamHi:
Thanks for your help! Your question is what I am trying hard now. Current procedure can only display one picture per person, however, I am supposed to write a new procedure which displays multiple pictures for one person. When user click a button on report, APEX should call this procedure and returns next picture of the same person. The table is SOR_image. However, I rewrite the HTML expression as follows to test to display the second image.
<img src="#OWNER#.Sor_Display_Current_Image?p_n_Offender_id=#OFFENDER_ID#&p_n_image_Count=2" width="75" height="75"> The procedure code is complied OK as follows:
create or replace
PROCEDURE Sor_Display_Current_Image(p_n_Offender_id IN NUMBER, p_n_image_Count in number) AS
v_mime_type VARCHAR2(48);
v_length NUMBER;
v_name VARCHAR2(2000);
v_image BLOB;
v_counter number:=0;
cursor cur_All_Images_of_Offender is
SELECT 'IMAGE/JPEG' mime_type, dbms_lob.getlength(image) as image_length, image
FROM sor_image
WHERE offender_id = p_n_Offender_id;
rec_Image_of_Offender cur_All_Images_of_Offender%ROWTYPE;
BEGIN
open cur_All_Images_of_Offender;
loop
fetch cur_All_Images_of_Offender into rec_Image_of_Offender;
v_counter:=v_counter+1;
if (v_counter=p_n_image_Count) then
owa_util.mime_header(nvl(rec_Image_of_Offender.mime_type, 'application/octet'), FALSE);
htp.p('Content-length: '||rec_Image_of_Offender.image_length);
owa_util.http_header_close;
wpg_docload.download_file (rec_Image_of_Offender.image);
end if;
exit when ((cur_All_Images_of_Offender%NOTFOUND) or (v_counter>=p_n_image_Count));
end loop;
close cur_All_Images_of_Offender;
END Sor_Display_Current_Image; The procedure just open a cursor to fetch the images belong to the same person, and use wpg_docload.download_file function to display the image specified. But it never works. It is strange because even I use exactly same code as before but change procedure name, Oracle APEX cannot display an image. Is this due to anything such as make file configuration in APEX?
Thanks
Sam -
Calling stored procedure from BC4J
How can I call a stored procedure in a JSP using the BC4J framework?
nullVitor,
Basically, you need to create a custom method from your JSP's ViewObject, which calls the stored procedure. You can then call the ViewObject's custom method from the JSP client.
Here is how I have done it:
1. Choose the ViewObject that your JSP is based on and choose 'Edit' from the context menu.
2. On the Java tab of the ViewObject wizard, choose Generate Java File checkbox for the View Object Class and click the Finish button. A file is created under the ViewObject node in the Navigator named 'viewobjectImpl.java'.
3. Open the viewobjectImpl.java file in the code editor and create a method to call your stored procedure (see sample code below).
4. Compile the VOImpl.java file.
5. Choose the view object again, and choose Edit again from the context menu.
6. On the Client Methods tab, you should now see your method appear in the Available field. Select it and shuttle it to the Selected field.
7. Click Finish to leave the VO wizard, and rebuild your Business Components project.
8. In your JSP, call the custom method (see sample code below).
sample code for custom method calling a stored procedure from VOImpl.java file:
public int getTotalHits(String mon, String year) {
CallableStatement stmt = null;
int total;
// the call to the PL/SQL stored proc
String totalhits = "{? = call walkthru.total_hits(?,?)}";
// use the AM conxn 2 call storedproc
stmt = getDBTransaction().createCallableStatement(totalhits, 1);
try
// Bind the Statement Parameters and Execute this Statement
stmt.registerOutParameter(1,Types.INTEGER);
stmt.setString(2,mon);
stmt.setString(3,year);
stmt.execute();
total = stmt.getInt(1);
catch (Exception ex)
throw new oracle.jbo.JboException(ex);
finally
try
stmt.close();
catch (Exception nex)
return total;
sample render code for calling custom method from JSP custom bean:
public void render() {
int totalhits;
try
Row[] rows;
// Retrieve all records by default, the qView variable is defined in the base class
qView.setRangeSize(-1);
qView.first();
rows = qView.getAllRowsInRange();
// instantiate a view object for our exported method
// and call the stored procedure to get the total
ViewObject vo = qView.getViewObject();
wtQueryView theView = (wtQueryView) vo;
totalhits = theView.getTotalHits(session.getValue("m").toString(),session.getValue("y").toString());
out.println(totalhits);
} catch(Exception ex)
throw new RuntimeException(ex.getMessage());
null -
JDBC performance calling stored procedures
Hi,
We have an java application which makes calls to PL/SQL stored procedures. We have one 'database server' component which handles all the database interaction, and other components which connect to it using CORBA.
The problem is that with everything running, certain queries are taking from 17 to 30 seconds to come back, but when you run the same sql from SQLPlus, you get the results back in about 2 seconds every time.
We're using a connection pool, but this doesn't seem to be the problem, as we put in diagnostics and it takes no time at all to get a free connection.
The time is taken up doing a getCursor() to get the result set back. We register the cursor as an output parameter, and open it from within the stored procedure.
Anyone any suggestions?
Thanks,
Neil.
nullHi ,
You can call stored procedure using JPA (eclipselink API).Below is the sample code
ReadAllQuery readAllQuery = new ReadAllQuery(Employee.class);
call = new StoredProcedureCall();
call.setProcedureName("Read_All_Employees");
readAllQuery.useNamedCursorOutputAsResultSet("RESULT_CURSOR");
readAllQuery.setCall(call);
List employees = (List) session.executeQuery(readAllQuery);
Regards,
Vinay -
Weird Problem calling Stored Procedure using JDBC
Scenario is..
I have J2EE application and calling stored procedure using JDBC.
My application connects to instance "A" of testDB.
Schema "A" does NOT own any packages/procedure but granted execute on oracle packages/procedures that reside in schema "B" of testDB.
In java code I call procedure(proc1) in package(pac1) which internally calls procedure(proc2) in package(pac2).
The problem occurs when procedure pac2.proc2 is modified. After the modification, my java code fails and throws an exception "User-Defined Exception" and I am also getting "ORA-06508: PL/SQL: could not find program unit being called". This clears up only if I bounce the web container. (This doesn't happen if I modify pac1.proc1 and run my application)
Has any one faced this problem? Please suggest if any thing can be changed in jdbc code to fix this problem.
ThanksHi,
I assume these are PL/SQL packages and that the changes are made at the package specification level?
If so, it looks like you are hitting the PL/SQL dependencies rules. In other words, if the spec of proc2 is changed, then proc1 is invalidated, since proc1 still depends on the old version of proc2's spec. As a result, if you try to run proc1, its spec must either be explicitly rewritten before it could run again or implicitly recompiled first, if the (implicit) recompilation fails, it won’t run.
Kuassi http://db360.blogspot.com -
Calling stored procedures in Sybase from java
Hi,
I am using the following stored procedure in Sybase
use xyzdb
go
-- drop procedure if it already exist
if object_id('up_name_select') is not null
begin
drop procedure up_name_select
end
go
create procedure up_name_select
@zid numeric(7,0),
@firstname char(40),
@lastname char(40)
as
select zid,
firstname,
lastname
from name
where zid = @zid or
(lastname like @lastname or firstname like @firstname)
go
-- update documentation records in object_docs
delete object_docs
from object_docs
where object_name = "up_name_select"
go
insert into object_docs values("up_name_select","Selects records from the name table based upon the values of the input parameters.")
go
-- update documentation records in column_docs
delete column_docs
from column_docs
where object_name = "up_name_select"
go
insert into column_docs values("up_name_select","@zid","System generated ID for an individual contact.")
insert into column_docs values("up_name_select","@firstname","First name of the contact. SQL wild card characters are accepted.")
insert into column_docs values("up_name_select","@lastname","Last name of the contact. SQL wild card characters are accepted.")
go
-- print success message and grant permissions
if object_id('up_name_select') is not null
begin
print "Procedure up_name_select created."
grant execute on up_name_select to developer_role
end
go
This stored procedure selects the values from the table "name" for a given where condition (if I am not wrong).
Can any one give me sample java code to select the records from the table "name" for a given zid.
Thankyou in advance.
Regards
sgatl2calling stored procedures from java
here is the sample code
CallableStatement cs = con.prepareCall("{call selectlogin (?)}");
cs.setString (1, "value");
ResultSet rs = cs.executeQuery ();
while (rs.next ())
//your code for display
} more on gooooooogle
http://www.google.com/search?q=calling+stored+procedures+from+java+with+sample+example&client=netscape-pp&rls=com.netscape:en-US -
Java call stored procedure with nested table type parameter?
Hi experts!
I need to call stored procedure that contains nested table type parameter, but I don't know how to handle it.
The following is my pl/sql code:
create or replace package test_package as
type row_abc is record(
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
type matrix_abc is table of row_abc index by binary_integer;
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
END test_package;
create or replace package body test_package as
PROCEDURE test_matrix(p_arg1 IN VARCHAR2,
p_arg2 IN VARCHAR2,
p_arg3 IN VARCHAR2,
p_out OUT matrix_abc
IS
v_sn NUMBER(8):=0 ;
BEGIN
LOOP
EXIT WHEN v_sn>5 ;
v_sn := v_sn + 1;
p_out(v_sn).col1 := 'col1_'||to_char(v_sn)|| p_arg1 ;
p_out(v_sn).col2 := 'col2_'||to_char(v_sn)||p_arg2 ;
p_out(v_sn).col3 := 'col3_'||to_char(v_sn)||p_arg3 ;
END LOOP ;
END ;
END test_package ;
My java code is following, it doesn't work:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@10.16.102.176:1540:dev", "scott", "tiger");
con.setAutoCommit(false);
CallableStatement ps = null;
String sql = " begin test_package.test_matrix( ?, ? , ? , ? ); end ; ";
ps = con.prepareCall(sql);
ps.setString(1,"p1");
ps.setString(2,"p2");
ps.setString(3,"p3");
ps.registerOutParameter(4,OracleTypes.CURSOR);
ps.execute();
ResultSet rset = (ResultSet) ps.getObject(1);
error message :
PLS-00306: wrong number or types of arguments in call to 'TEST_MATRIX'
ORA-06550: line 1, column 8:
PL/SQL: Statement ignored
Regards
LouisLouis,
If I'm not mistaken, record types are not allowed. However, you can use object types instead. However, they must be database types. In other words, something like:
create or replace type ROW_ABC as object (
col1 varchar2(16),
col2 varchar2(16),
col3 varchar2(16 )
create or replace type MATRIX_ABC as table of ROW_ABC
/Then you can use the "ARRAY" and "STRUCT" (SQL) types in your java code. If I remember correctly, I recently answered a similar question either in this forum, or at JavaRanch -- but I'm too lazy to look for it now. Do a search for the terms "ARRAY" and "STRUCT".
For your information, there are also code samples of how to do this on the OTN Web site.
Good Luck,
Avi. -
Memory leak problem while passing Object to stored procedure from C++ code
Hi,
I am facing memory leak problem while passing object to oracle stored procedure from C++ code.Here I am writing brief description of the code :
1) created objects in oracle with the help of "create or replace type as objects"
2) generated C++ classes corresponding to oracle objects with the help of OTT utility.
3) Instantiating classes in C++ code and assigning values.
4) calling oracle stored procedure and setting object in statement with the help of setObject function.
5) deleted objects.
this is all I am doing ,and getting memory leak , if you need the sample code then please write your e-mail id , so that I can attach files in reply.
TIA
Jagendrajust to correct my previous reply , adding delete statement
Hi,
I am using oracle 10.2.0.1 and compiling the code with Sun Studio 11, following is the brief dicription of my code :
1) create oracle object :
create or replace type TEST_OBJECT as object
( field1 number(10),
field2 number(10),
field3 number(10) )
2) create table :
create table TEST_TABLE (
f1 number(10),f2 number (10),f3 number (10))
3) create procedure :
CREATE OR REPLACE PROCEDURE testProc
data IN test_object)
IS
BEGIN
insert into TEST_TABLE( f1,f2,f3) values ( data.field1,data.field2,data.field3);
commit;
end;
4) generate C++ classes along with map file for database object TEST_OBJECT by using Oracle OTT Utility
5) C++ code :
// include OTT generate files here and other required header files
int main()
int x = 0;
int y = 0;
int z =0;
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
Connection* const pConn =
env->createConnection"stmprf","stmprf","spwtrgt3nms");
const string sqlStmt("BEGIN testProc(:1) END;");
Statement * pStmt = pConn->createStatement(sqlStmt);
while(1)
TEST_OBJECT* pObj = new TEST_OBJECT();
pObj->field1 = x++;
pObj->field2 = y++;
pObj->field3 = z++;
pStmt->setObject(1,pObj);
pStmt->executeUpdate();
pConn->commit();
delete pObj;
} -
How to call stored procedures from java program?
I have tried to run a program that calls a stored procedure on MySQL
server version 5.0.17 by using connector/j 5.0, but it always fails on the
statement: con.preparecall() ,
have looked on the internet and found out that people can all mysql
stored procedure all right in their programs, really dont know what's
wrong with this small peiece of code:
import java.sql.*;
public class TestDB {
// procedure being called is:
CREATE PROCEDURE `dbsaystorm`.`getsite` ()
BEGIN
select name from tblsite;
END
public static void main(String[] args) {
try {
//Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbname",
"user", "pwd");
* executing SQL statement here gives perfect correct results:
// PreparedStatement ps = con.prepareStatement("select name from tblsite");
// ResultSet rs =ps.executeQuery();
// but in stored procedure way...
//it fails here on this prepare call statement:
CallableStatement proc = con.prepareCall("call getsite()");
ResultSet rs =proc.executeQuery();
if (rs == null) return;
while (rs.next()){
System.out.println("site name is: "+ rs.getString(1));
rs.close();
} catch (SQLException e) {e.printStackTrace();}
catch (Exception e) {e.printStackTrace();}
}it always gives this exception:
java.lang.NullPointerException
at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:959)
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1280)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3668)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:638)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:453)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4365)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4439)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4413)
at saystorm.server.data.database.TestDB.main(TestDB.java:29)
where have I gone wrong?
when I commented out the statement that makes the procedure call and call preparedstatement to execute SQL select statement, it gave perfectly correct result.
it looks like there is no problem with java prog accessing MYSQL server database, but the it seems that it's just java can't call stored procedure stored on the mysql server version 5.
can it or can't it? if it can, how is that accomplished?It is a bug in the driver because it shouldn't be
returning that exception (null pointer) even if you
are doing something wrong.
Are you using the latest version of the driver?
The stored procedure runs when you run it from the
gui/command line using a MySQL tool - correct?
As suggested you should be using the brackets. What
is the data type of the 'name' field?
You could try returning another value like one of the
following
select 1, name from tblsite;
select name, 1 from tblsite;
That might get around the bug
Additionally try just the following...
select 'test' from tblsite;yes, the driver used is in connector/j 5.0--the lastest one, and the
procedure can run correctedly at either command line or GUI mode
with no problem whatsoever, the returned data type is string type,
I have not got the chance to test it again with those values you
suggested, as I have abandoned the laptop I used to write that code
initately. There have been some other really weird cases happened on
that computer. I guess that must be something wrong with the JVM
installed on it, it was upgraded from jre5.0.04 to 06, and to 09.
something within hte JVM must have been messed up(the only reasonable
explanation). Because the same code runs correctly on my new laptop,
using the same environment: jvm 5.0_09, mysql 5.0.18, connector/J 5.0.
that old laptop really was a nightmare.
Maybe you are looking for
-
I had my rescue email set to my old school email account, but they changed the emails a couple of years ago, so I can't access it. I can log into the itunes/app store, but when I hit view account, it doesn't accept my password. I also can't remember
-
Windows 8 and icloud photo streem's problem
Hello I am Windows 8 user I have a problem related to photo stream I take the photo with Iphone and I can send to my computer. But I can't send photo computer to Iphone. Everything is activated operating system : windows 8 pro icloud version : 2.1.1
-
5600FX S-Video signal but no Composite signal
Hi, I have just build my new PC, MoBo MSI KT6 Delta, and graphics MSI 5600FX 128Mb, as you can see I like MSI, My problem, when I connect my TV (Composite connector) to the Graphic card(Conversor cable S-Video to Composite) I select in the nvidia opt
-
E51 Balance checking restart Necessary
After calling someone from airtel( Airtel is network operator in India) if Balance checking is done using *123# immediately after call, you get message balance could not be known. After this, Then Contacts calling wont happen at all and checking bala
-
I purchased an Iomega 1TB external HD and see where it has some software that comes with it. The HD has the HFS+ so it is Mac ready out of the box, question is this: will this other software make things more complicated as I am only wanting this to w