【问题标题】:Java: Calling a stored-procedure I get mysql errorJava:调用存储过程我得到 mysql 错误
【发布时间】:2019-11-05 01:22:52
【问题描述】:

我正在尝试使用存储过程在 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) 

【问题讨论】:

    标签: java mysql stored-procedures


    【解决方案1】:

    我认为问题可能出在您程序的签名上。 但时区也有问题,这里有一个检查这个的帖子。 enter link description here

    【讨论】:

    • 谢谢 davidza5。事实上,问题在于我的存储过程的签名。它的名称有一个空格字符insert_eD_dispensed medication。我将它重命名为 insert_eD_dispensed_medication`,现在它可以工作了!谢谢!
    猜你喜欢
    • 2012-12-11
    • 2014-03-07
    • 2013-05-18
    • 2014-11-23
    • 2016-02-08
    • 2023-03-23
    • 1970-01-01
    • 2018-02-09
    • 2018-12-29
    相关资源
    最近更新 更多