I have this mapper:
<insert id="insertBatch" parameterType="java.util.Set">
<foreach collection="filterParameterEntitySet" item="item" separator=";">
INSERT INTO filter_parameter
(
filter_key,
filter_value,
filter_id
)
VALUES
(
#{item.filterKey},
#{item.filterValue},
#{item.filter.id}
)
ON CONFLICT DO NOTHING
</foreach>
</insert>
Whenever I execute it, it throws BadSQLGrammarException:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: 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 'CONFLICT DO NOTHING
**
;
INSERT INTO filter_parameter
f' at line 13**
What could be the problem? I can't figure out where does the syntax error lie!
Try this:
<insert id="insertBatch" parameterType="java.util.Set">
INSERT INTO filter_parameter
(
filter_key,
filter_value,
filter_id
) VALUES
<foreach collection="filterParameterEntitySet" item="item" separator=",">
(
#{item.filterKey},
#{item.filterValue},
#{item.filter.id}
)
</foreach>
ON CONFLICT DO NOTHING
</insert>
So basically, there were 2 mistakes in the query:
The separator, instead of this: separator=";"
I should use this: separator=","
ON CONFLICT DO NOTHING is not valid in mysql and I was using mysql (it's for postgres), so I removed it and added the keyword IGNORE after INSERT to reserve the same functionality
Related
Sequence Strategy for MYSQL not working
I have an Id defined in my entity:
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
When persisting an entity I get the following error. I checked several hints, but noone worked for me.
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: 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 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1
Error Code: 1064
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [2 parameters bound]
Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
MYSQL Version : 8
SQL "UPDATE SEQUENCE ..." can be executed from the workbench without problems. "OPTION SQL_SELECT_LIMIT=DEFAULT" seems not to be valid.
I guess "OPTION SQL_SELECT_LIMIT=DEFAULT" is coming implicitely when .persist() is called, because of the sequence strategie.
Any help hints ?
UPDATE
Switching to
strategy = GenerationType.IDENTITY
does not invoke "OPTION SQL_SELECT_LIMIT=DEFAULT" and it works fine. Strange.
I use Liquibase on Mysql and got a below error when trying create function
Unexpected error running Liquibase: You have an error in your SQL
syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near 'in varchar2) return varchar2
is
This is my function file MyFunction.sql:
create or replace function MyFuncion(p_id in varchar2)
return varchar2 is Result varchar2(50);
begin Result := 'bbbb' || p_id;
return(Result); end MyFuncion;
End my changelog
<changeSet author="taibc" id="sqlFile-example2">
<sqlFile dbms="ttdp_thanh, mysql"
encoding="utf8"
endDelimiter="\n/"
path="MyFunction.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
<rollback>
DROP Function MyFunction;
</rollback>
</changeSet>
Can you help me ?
I'm getting an error while trying to query a custom table using the wpdb class. Here is my code :
global $wpdb;
$dates_bloquees = $wpdb->query(
$wpdb->prepare( "SELECT datesbloquees FROM $wpdb->datesbloquees WHERE idproduit = '%d' ", $postid ) );
Error message :
WordPress database error: [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 'WHERE idproduit = '1'' at line 1]
Can someone tell me what I'm doing wrong?
Thank you for your help,
François
SELECT `template_id`, replace(template_code,"AT -","DE -") as
template_code, `template_text`, `template_styles`, `template_type`,
`template_subject`, `template_sender_name`, `template_sender_email`,
`added_at`, `modified_at`, `orig_template_code`, `orig_template_variables`
FROM `core_email_template` WHERE template_code like "%AT - %"
This query it works and returns me some data that I want to export it. But when I do that from phpmyadmin I received this error:
Error reading data: (#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the
right syntax to use near 'FROM WHERE
(`core_email_template`.`template_id` = 27) OR (`core_email_template' at
line 1)
What should I have to do to make this work ? thx
This is my Code of Stored Function:
CREATE DEFINER=`root`#`localhost` FUNCTION `func`()
RETURNS int(11)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE total INT DEFAULT 0;
select count(*) INTO total from students;
RETURN total;
END
Java Code:
query=em.createNativeQuery("{ SELECT func() }");
String s=(String) query.getSingleResult();
System.out.println(s);
But ir gives an Exception:
Internal Exception: 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 '{ SELECT func() }' at line 1
Error Code: 1064
Call: { SELECT func() }
Query: DataReadQuery(sql="{ SELECT func() }")
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: 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 '{ SELECT func() }' at line 1
Error Code: 1064
Call: { SELECT func() }
Query: DataReadQuery(sql="{ SELECT func() }")
at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:377)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:516)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
at org.ceynamon.oregano.datamigration.Test.main(Test.java:26)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;
The braces around SELECT funct() are not needed