[英]Java: Calling a stored-procedure I get mysql error
我正在嘗試使用存儲過程在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)
我認為問題可能出在你的程序的簽名上。 但是還有時區的問題,這里有一個檢查這個的帖子。 在此輸入鏈接描述
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.