简体   繁体   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 code(Procedure) // 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

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 ' 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 ' 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 ' )' 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 '

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;

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

相关问题 为什么在绑定中调用get的绑定值会引发stackoverflow错误 - Why does calling get of a bound value in the binding throw a stackoverflow error 在mysql中调用存储过程时出错(JAVA休眠) - Error when calling the Stored procedure in mysql(JAVA hibernate) 为什么递归调用此函数不会引发NullPointerException - Why calling this function recursively does not throw a NullPointerException 为什么 Hibernate 在调用 session.save(object) 时会抛出 ClassCastException? - Why does Hibernate throw a ClassCastException when calling session.save(object)? 通过Java调用存储过程(MySql)时出错 - Error in calling Stored Procedure(MySql) through Java 为什么此代码为什么在*和+运算符上引发invalidAssignmentOperator错误? - Why does this code throw an invalidAssignmentOperator error on the * and + operators? 为什么这会引发“空对象引用”错误? - Why does this throw a 'null object reference' error? 为什么这会引发错误/根本不运行? - Why does this throw an error/not run at all? 为什么 Selenium 使用 assertEquals 会抛出错误? - Why does Selenium throw an error with assertEquals? 为什么我的程序会抛出此JNI错误? - Why does my program throw this JNI error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM