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
为什么会出现这个错误?如何解决?
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 '
j )' at line 1
帮帮我 请
答案 0 :(得分:0)
试试这个:
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;