• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting error while working Stored procedure?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
database : mysql


here java callable statement program (in eclipse):

static Connection con = null;
static CallableStatement st = null;

public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
//Connection
con = DriverManager.getConnection("jdbc:mysql://localhost/orcl","root","pspl");
System.out.println("Connected");
//Statement st = null;
st=(CallableStatement) con.prepareCall("{call ins(?,?)}");
//((CallableStatement) st).setInt(1,121);
//((CallableStatement) st).setString(2,"harish");
st.setInt(1,121);
st.setString(2,"harish");
st.execute();
}
catch(Exception e)
{
e.printStackTrace();
}


and here

mysql> create procedure ins(a IN int, b IN varchar)
-> as
-> begin
-> insert into emp values(a,b);
ERROR 1064 (42000): 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 'IN in
t, b IN varchar)
as
begin
insert into emp values(a,b)' at line 1


why it is getting error? and tell me how to execute these function?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The order of you parameter clause looks wrong. According to the documentation it should be :


proc_parameter:
[ IN | OUT | INOUT ] param_name type

 
rohithrs
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mysql> create procedure ins(IN a int, IN b varchar(20))
-> as
-> begin
-> insert into emp values(a,b);
ERROR 1064 (42000): 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 'as
begin
insert into emp values(a,b)' at line 2


for that also getting error...
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm no expert on MySQL, but I don't think it supports the AS keyword. Check the documentation for the syntax of stored procedures to be sure.
 
rohithrs
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.....

i got Ans..,
reply
    Bookmark Topic Watch Topic
  • New Topic