繁体   English   中英

为什么MySQL在调用过程时抛出错误

[英]Why does MySQL throw an error when calling a procedure

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;
import java.util.Scanner;

class procedureTest
{
    public static void main(String[] args) {
        try{

            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/collection","collec","1234");
            CallableStatement stmt=con.prepareCall("{call getJob(?,?)}");
            Scanner s=new Scanner(System.in);
            System.out.println("enter the id");
            int id=s.nextInt();
            stmt.setInt(1, id);
            stmt.registerOutParameter(2,Types.VARCHAR);
            stmt.execute();
            System.out.println("job is"+stmt.getString(1));
            con.close();
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }

// pl sql代码(操作步骤)

 DROP PROCEDURE `getJob`; CREATE DEFINER=`collec`@`localhost` PROCEDURE `getJob`(IN `empId` INT(4), OUT `j` VARCHAR(20)) NOT DETERMINISTIC READS SQL DATA SQL SECURITY DEFINER begin select job into j from emp where id=empId; end

为什么会出现此错误?如何解决?

com.mysql.jdbc.exceptions.MySQLSyntaxErrorExceptionYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 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 ' )' at line 1 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 ' j )' at line 1 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 '

请帮帮我

尝试这个:

CREATE PROCEDURE getJob (IN empId INT(4), OUT j VARCHAR(20)) NOT DETERMINISTIC READS SQL DATA SQL SECURITY DEFINER begin select job into j from emp where id=empId; end;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM