2009-08-04 16 views
0
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(); 
} 
} 

JDBCプログラム(ストアドプロシージャ)MYSQLで

fileproc: 
CREATE PROCEDURE fileproc(IN x INT,OUT y INT) 
BEGIN 
y := x * x; 
END; 
/

fileprocでENDに入る前に、私は3行でエラーを取得しています

として
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. 

正しい構文は何ですか? 助けてください。 ありがとうございます。

答えて

0
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; 
+0

いくつかのコードの説明を追加できますか? – user35443

関連する問題