有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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。例外。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 'j)' at line 1

帮帮我 求你了


共 (1) 个答案

  1. # 1 楼答案

    试试这个:

    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;