MySQL syntax error - Java Bukkit / Spigot plugin [closed] - java

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm getting this error when I'm trying to connect my Java Plugin to the local MySQL database:
[01:15:44 INFO]: [BetterStaff] Could not connect to database: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 ''Reportslog' ('SenderName' varchar(32), 'Message' string)' at line 1
The code from my plugin is:
this.db.openConnection();
Statement statement = this.db.getConnection().createStatement();
statement.executeUpdate("CREATE TABLE IF NOT EXISTS 'Reportslog' ('SenderName' varchar(32), 'Message' string)");
Can you help me or correct my SQL syntax please?

Quotes are not allowed in the table name or fields:
String sql =
"CREATE TABLE IF NOT EXISTS Reportslog (SenderName varchar(32), Message varchar(32))";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.executeUpdate();

Related

JDBC delete method seems to not be working in my Spring Boot service [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm trying to create a simple JDBC method to delete from my DB, and I'm not sure if I'm going about this the correct way. This is inside one of my services.
Method:
public void deleteLocation(Integer id) {
String DELETE = "DELETE FROM locale WHERE id=?";
namedParameterJdbcTemplate.update(DELETE, new BeanPropertySqlParameterSource(id));
}
I would try changing your update line to
namedParameterJdbcTemplate.update(DELETE, id);.
If you are using spring-boot. Then you should be using spring-data-jpa to manage your database. Jdbc is Hard way of doing this.
If you are using jdbc delete to a specific row use prepared statement. You can refer this:
preparedStatement = connection.prepareStatement("DELETE * from table_name WHERE id= ?");
preparedStatement.setInt(1, id);
return !preparedStatement.execute();

i cannot locate this problem keep getting mysql syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
String sql="insert into std(StudentID,Surname,Name,CourseCode,Maths,English,Physics,Biology,Chemistry,Psychology,HealthScience,Religion"+"TotalScore,Average,Ranking)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";`
` try{
`pst=conn.prepareStatement(sql);`
`pst.setString`(1, jTextField14.getText());`
` pst.setString(2, jTextField1.getText());`
` pst.setString(3, jTextField2.getText());`
` pst.setString(4,(String) jComboBox1.getSelectedItem());`
` pst.setString(5, jTextField6.getText());`
`pst.setString(6, jTextField7 .getText());`
` pst.setString(7, jTextField8.getText());`
` pst.setString(8, jTextField9.getText());`
`pst.setString(9, jTextField10.getText());`
`pst.setString(10, jTextField11.getText());`
` pst.setString(11, jTextField12.getText());`
` pst.setString(12, jTextField13.getText());`
`pst.setString(13, jTextField3.getText());`
`pst.setString(14, jTextField4.getText());`
` pst.setString(15, jTextField5.getText());`
`pst.execute();`
`JOptionPane.showMessageDialog(null, "system update completed");`
`rs.close();`
` pst.close();`
`}catch(Exception e){`
`JOptionPane.showMessageDialog(null, e);`
` }`
` } `
i keep getting this error error in sql syntax check for error that corresponds to mysql manual near
Although the error message is missing, it's probably in consequence of calling an incompatible setter method for one or more parameters.
For example, an id column is usually a number. Hence, based on the data type of this column, you have to call the corresponding setter method (setInt, setLong).
To get more information about PreparedStatements and its methods, read this document:
docs.oracle.com:PreparedStatement.html

Prepared Statement with subquery Gives Syntax Errror [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
PreparedStatement amovie = con.prepareStatement("INSERT INTO actor_movie(actor_ID, movie_ID)"+ "select actor_ID from actor" + "where actor.surname = 'Depp', select movie_ID from movie where movie.title LIKE 'Caribbean%'");
Can someone tell me what is wrong with this query ? I digged the internet, but can't find a solution.
Error Message :
Exception in thread "main" 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 movie_ID from movie where title LIKE 'Caribbean%'' at line 1
You have syntax error because you forgot VALUES and to enclose in parentheses the SELECT statements.
Change to this:
PreparedStatement amovie = con.prepareStatement(
"INSERT INTO actor_movie(actor_ID, movie_ID) VALUES ((select actor_ID from actor where actor.surname = 'Depp'), (select movie_ID from movie where movie.title LIKE 'Caribbean%'))");
Careful with the spaces needed between the strings concatenate
...movie_ID)"+ "select ...

What is the reason for this query is not working? Got: MySQLSyntaxErrorException Unknown column [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
My columns at customer table
cusid cusname cusadress paidamount email
cus123 damidu kegalle 45 adfff
This is my Java query
String query = "UPDATE `customer` SET `cusname`='"+jTextField_name.getText()+"',`cusadress`='"+jTextField_adress.getText()+"',`paidamount`='"+jTextField_amount.getText()+"',`email`="+jTextField_emailuser.getText()+" WHERE `cusid` = "+jTextField_id.getText();
executeSQlQuery(query, "Updated");
Error
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'cus123' in 'where clause'
What is the reason for this update is not working , but insert and delete statement works?
Use PreparedStatement like this below :
String updateQuery = "UPDATE customer SET cusname=?,cusadress=?,paidamount=?,email=? WHERE cusid=?";
PreparedStatement stmt=con.prepareStatement(updateQuery); // con is reference variable of Connection class
stmt.setString(1, jTextField_name.getText());
stmt.setString(2, jTextField_adress.getText());
stmt.setInt(3, jTextField_amount.getText());
stmt.setString(4, jTextField_emailuser.getText());
stmt.setString(5, jTextField_id.getText());
Hope this helps.

ORA-00933: SQL command not properly ended in a query that runs fine in SQL developer [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Below code gives
ORA-00933: SQL command not properly ended
on
private final String DUPLICATE_SQL_1="select abc, count(abc)"
+"from table_1"
+"where type= 'NEW'"
+"and trunc(update_date) = trunc(sysdate)"
+"group by abc having count(abc)>1";
ResultSet rs = stmt.executeQuery(DUPLICATE_SQL_1);
Same query worked fine on Oracle SQL Developer.
You are missing spaces (you must have a space at the end of each line except the last or at the start of each line except the first):
private final String DUPLICATE_SQL_1="select abc, count(abc) "
+"from table_1 "
+"where type= 'NEW' "
+"and trunc(update_date) = trunc(sysdate) "
+"group by abc having count(abc)>1";

Categories