473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Problem in select stmt inside stored procedure

5
Hello, i've a problem regarding the select stmt inside the stored procedure.

Here's my code:
Expand|Select|Wrap|Line Numbers
  1. DELIMITER $$
  2.  
  3. DROP PROCEDURE IF EXISTS `p`.`getNames`$$
  4.  
  5. CREATE PROCEDURE `p`.`getNames`(q varchar)
  6.     /*LANGUAGE SQL
  7.     | [NOT] DETERMINISTIC
  8.     | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
  9.     | SQL SECURITY { DEFINER | INVOKER }
  10.     | COMMENT 'string'*/
  11.     BEGIN
  12.     exec q;
  13.  
  14.     END$$
  15.  
  16. DELIMITER ;
  17.  
i want to execute the variable q.

for ex: (from the java class)
Expand|Select|Wrap|Line Numbers
  1. q = "select * from user where username = '"+u+"' AND name = '"+n+"';";
  2.  
then i'll just pass it to the stored procedure. however, that doesn't work, there's an error that says

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | R' at line 1

there are certain conditions in the java class so q varies depending on the user inputs.

please help me.

Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
Mar 5 '08 #1
8 3942
amitpatel66
2,367 Expert 2GB
Hello, i've a problem regarding the select stmt inside the stored procedure.

Here's my code:

DELIMITER $$

DROP PROCEDURE IF EXISTS `p`.`getNames`$$

CREATE PROCEDURE `p`.`getNames`(q varchar)
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
exec q;

END$$

DELIMITER ;

i want to execute the variable q.

for ex: (from the java class)
q = "select * from user where username = '"+u+"' AND name = '"+n+"';";

then i'll just pass it to the stored procedure. however, that doesn't work, there's an error that says

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | R' at line 1


there are certain conditions in the java class so q varies depending on the user inputs.

please help me.
Try this query:

Expand|Select|Wrap|Line Numbers
  1.  
  2. q = "select * from user where username = '" +u+"' AND name = '"+n+"'";
  3.  
  4.  
Mar 5 '08 #2
yrrah
5
Try this query:

Expand|Select|Wrap|Line Numbers
  1.  
  2. q = "select * from user where username = '" +u+"' AND name = '"+n+"'";
  3.  
  4.  
Ah..what i want to do is create a stored procedure that will execute any query that i like to pass. the query would vary depending on the java class. the java class would then pass it to the mysql.
Mar 6 '08 #3
amitpatel66
2,367 Expert 2GB
Ah..what i want to do is create a stored procedure that will execute any query that i like to pass. the query would vary depending on the java class. the java class would then pass it to the mysql.
Yes but its just a syntax error and its probably because the semicolon that you had placed at the end of your query. I removed a semi colon and have you tested that query or it does not work either?
Mar 6 '08 #4
yrrah
5
Yes but its just a syntax error and its probably because the semicolon that you had placed at the end of your query. I removed a semi colon and have you tested that query or it does not work either?
I've tried it out already but it doesn't work.:(
It says:

Error Code : 1243
Unknown prepared statement handler (q) given to EXECUTE

what does this mean?

thanks for your help!
Mar 6 '08 #5
amitpatel66
2,367 Expert 2GB
I've tried it out already but it doesn't work.:(
It says:

Error Code : 1243
Unknown prepared statement handler (q) given to EXECUTE

what does this mean?

thanks for your help!
Could you please post your java source that defines variable q for reference? Now this error is due to some java code and the SQL statement is fine.
Mar 6 '08 #6
yrrah
5
Could you please post your java source that defines variable q for reference? Now this error is due to some java code and the SQL statement is fine.
i'm using sqlyog. so i call it in the query tab.

what i did is this:

call sp_name('select * from person');
Mar 7 '08 #7
amitpatel66
2,367 Expert 2GB
i'm using sqlyog. so i call it in the query tab.

what i did is this:

call sp_name('select * from person');
Is your procedure running fine when you pass this select statement??
Mar 7 '08 #8
yrrah
5
Is your procedure running fine when you pass this select statement??
Hi, I already got this one. thanks for your help!!!

:D:)
Mar 9 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: usenet | last post by:
Hi. I have a DB2 stored procedure that I call using JDBC. Now I'm trying to batch the call. This is done by the book: stmt = connection.prepareCall(" ... "); stmt.setString(1, "foo");...
4
by: mattgcon | last post by:
When I use a stored procedure to insert data into a table and when the Datagrid refreshes two new columns are added. The dataSet is set up with one table with NO columns defined. Please help me on...
6
by: Not4u | last post by:
Hello Config : SQL 2000 on WIN 2000 (IIS 5.0) In my ASP page for some queries i have this error : Microsoft OLE DB Provider for SQL Server error '80040e31' Timeout expired
5
by: mk | last post by:
Hi all, The requirement is like this.. I have to update the table with the parameters from front end like at some times i need to update one parameters and some times i have to update more...
1
by: eRTIS SQL | last post by:
hi, I want to use a stored procedure inside a stored procedure simulteanously changing the database. this is my base store procedure alter PROCEDURE create_file @dbname sysname AS declare...
1
by: amgupta8 | last post by:
Note: This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2. Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and...
1
by: Kingsly | last post by:
How to read "stmt" column of "sysibm.syspackstmt" table in a readable format? select stmt from sysibm.syspackstmt where name like 'MYPROC1'; I was expecting the stored procedure statements as...
5
by: Mark A | last post by:
"Serge Rielau" <srielau@ca.ibm.comwrote in message news:6i5c4rFoto1gU1@mid.individual.net... When are we getting the execute immediate for "select ... into..." that you mentioned about 3 years...
0
by: pankaj17 | last post by:
hello everyone, MYSQL query ............ how to set prepare stmt result in variable i have written prepare stmt in store procedure and i want to set result of prepare stmt in variable ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.