import java .sql.*;
class Pro
{
public static void main(String args[]) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test";
Connection conn = DriverManager.getConnection (url,"root","password");
CallableStatement cst=conn.prepareCall("{call fileproc(?,?)}");
cst.setInt(1,10);
cst.registerOutParameter(2,Types.INTEGER);
cst.execute();
int i=cst.getInt(2);
System.out.println("the number is :" +i);
cst.close();
conn.close();
}
}
In MYSQL:
fileproc:
CREATE PROCEDURE fileproc(IN x INT,OUT y INT)
BEGIN
y := x * x;
END;
/
i'm getting an error at line 3 before entering END in fileproc as
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 ':= x
* x' at line 3.
what is the correct syntax? please help. Thank You.
mysql>create database <database-name>;
->use <database-name>;
delimiter //
Create Procedure fileproc(in x int, out y int)
begin
set y = x * X;
end //
mysql> delimiter ;
mysql> call(10,@y);
mysql> Select @y;
In the mysql store procedure, remember to use 'set' keyword.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.