Java:调用存储过程时出现 mysql 错误

标签 java mysql stored-procedures

我正在尝试使用存储过程在 mysql 中添加 yyyy-mm-dd 格式的日期值。

如果我调用mysql内的存储过程,我可以正确插入相同的数据。

但是,当我尝试通过 java 调用它时,出现错误:

com.mysql.jdbc.exceptions.jdbc4.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 'medication(1005,51,'2' at line 1

我的存储过程是:

CREATE DEFINER=`xxx`@`localhost` PROCEDURE `insert_eD_dispensed medication`(IN `prescription_mapping_id` int(11), IN  `patient_id` int(11),   IN `date_of_dispense` date )
    NO SQL
INSERT INTO `prescription_dispensation_mapping` (`prescription_mapping_id`,  `patient_id`,  `date_of_dispense` )

调用的是:

public boolean insert_eD_dispensation (String prescription_mapping_id,  String patient_id,  String date_of_dispense) {
        Connection conn = this.getDBMySQLCon();
        String queryString;
        PreparedStatement preparedStmt = null;
        try {
            queryString = " {CALL insert_eD_dispensed medication(?,?,?)}";
            preparedStmt = conn.prepareStatement(queryString);

            preparedStmt.setInt(1, toInteger(prescription_mapping_id));
            preparedStmt.setInt(2, toInteger(patient_id));
            preparedStmt.setDate(3, java.sql.Date.valueOf(date_of_dispense));
            preparedStmt.execute();
            conn.close();
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }

java方法的调用是:

String prescription_mapping_id="1005"; 
String patient_id="1"; 
String date_of_dispense="2019-06-19"; 

boolean x = insert_eD_dispensation(prescription_mapping_id, patient_id, date_of_dispense) 

最佳答案

我认为问题可能出在你的程序的签名中。 但也有时区问题,这里有一篇文章用于检查这一点。 enter link description here

关于Java:调用存储过程时出现 mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56716189/

相关文章:

mysql - Google Big Query - 连接年份范围

mysql - 存储过程 OUT 返回空值

java - 使用 CrudRepository 只提取某些字段?

java - 需要针对 Java 中的这段代码进行澄清

php - Cakephp 3 newEntity() 不工作

c# - 获取EF6中存储过程的返回值

sql - 执行存储过程和查询的区别(因类型算术溢出)

java - 对话框 fragment 定位

java - 我正在尝试编写一个包含 2 个赛车手的程序,但它一直给我一个 IllegalThreadStateException

mysql - 计算并连接两个表