• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting error while working Stored procedure?

 
rohithrs
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks.....

i got Ans..,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic