简体   繁体   中英

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 code(Procedure)

 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

why is this error coming?how to solve it?

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException : 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 ' 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

help me out please

尝试这个:

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;

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.

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