Java sql syntax check

[Solved] JDBC: 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…

java.sql.SQLSyntaxErrorException is sub class of java.sql.SQLException which occurs in JDBC while executing any SQL query not following syntax or any typo mistake with keywords. Here trying to drop database schema.

Constructors

  • SQLSyntaxErrorException() : Construct a SQLSyntaxErrorException Object.
  • SQLSyntaxErrorException(String reason) : Construct a SQLSyntaxErrorException Object with a given reason.
  • SQLSyntaxErrorException(String reason, String SQLState) : Construct a SQLSyntaxErrorException Object., with a given reason and SQLState.
  • SQLSyntaxErrorException(String reason, String SQLState, int vendorCode) : Construct a SQLSyntaxErrorException Object .with a given reason, SQLState and vendorCode .
  • SQLSyntaxErrorException(String reason, String SQLState, int vendorCode, Throwable cause) : Construct a SQLSyntaxErrorException Object .with a given reason, SQLState vendorCode and cause . .
  • SQLSyntaxErrorException(String reason, String SQLState, ,Throwable cause) : Construct a SQLSyntaxErrorException Object .with a given reason, SQLState and cause . .
  • SQLSyntaxErrorException(tring reason, Throwable cause) : Construct a SQLSyntaxErrorException Object with reason and cause.
  • SQLSyntaxErrorException( Throwable cause) : Construct a SQLSyntaxErrorException Object with cause.

Sample Code

try < Class.forName("com.mysql.jdbc.Driver"); Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/", "root", "facingissuesonit"); Statement smt = conn.createStatement(); System.out.println("Drop Database . "); smt.executeUpdate("drop database ifexist FacingIssuesOnITDB"); System.out.println("Database drop successfully . "); >> catch (ClassNotFoundException ex) < ex.printStackTrace(); >catch (SQLException ex) < ex.printStackTrace(); >catch (SQLSyntaxErrorException ex)

Output Message

 java.sql.SQLException: Can't drop database 'facingissuesonitdb'; database doesn't exist at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1393) at com.mysql.cj.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2353) at com.mysql.cj.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1303) at com.fioit.jdbc.examples.schemasetup.DatabaseOperationTest.dropDatabase(DatabaseOperationTest.java:59) at com.fioit.jdbc.examples.schemasetup.DatabaseOperationTest.main(DatabaseOperationTest.java:19) 

Issue

java.sql.SQLSyntaxErrorException occurs in JDBC SQL query because of typo mistake there should space between two words ifexist that what throwing this exception.

Читайте также:  Php pdo database name

Solutions

Use correct query as below for dropping database.

Drop Database:

drop database if exists FacingIssuesOnITDB

Issues Solution

For more other JAVA/JDBC issues solution follow link JDBC Issues and Solutions.

Источник

Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the

There is a problem when adding, deleting, modifying and querying the interface of a table, as shown in figure

Error codes are as follows:

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 'DESCRIBE , CREATE_TIME, CREATED, UPDATE_TIME, UPDATED from renew_rul' at line 3 ; bad SQL grammar []; nested exception is 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 'DESCRIBE , CREATE_TIME, CREATED, UPDATE_TIME, UPDATED from renew_rul' at line 3 

Prompt me that my SQL syntax is abnormal. I have searched the Internet for a long time, but I haven’t found a similar problem. I specially record it,

The database used is MySQL and the database graphical interface Navicat.

The reason for the problem is that description is a keyword, which needs further processing in mybatis, but it’s strange that status should also be a keyword. Why doesn’t it report an error?

Solution: change the description field to des so that it can be compiled.

Read More:

  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
  • Error querying database.Cause:java.sql.SQLSyntaxErrorException:ORA-00911:invalid character
  • An error is reported about import Java. SQL. *; problem
  • This function has none of deterministic, no SQL, or reads SQL data in its error records
  • SQL state [null]; error code [0]; Error; nested exception is java.sql.SQLException: Error] with root
  • Spring data JAP SQL error:17059 SQL State:99999
  • Cause: java.sql.BatchUpdateException: Unknown column ‘xxx‘ in ‘field list‘
  • Hive SQL syntax error and corresponding solutions
  • SQL 2005 remote connection error (provider: SQL network interface, error: 28 – the server does not support the requested protocol
  • SAP SQL error “SQL code: -10692“ occurred while accessing table “ZTXXXX“.
  • DB2 SQL ERROR: SQLCODE=-803, SQLSTATE=23505, SQL
  • Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNot
  • Java 11.0.11 SQL Server connection error
  • java.sql.SQLException: Incorrect string value:
  • com.alibaba.druid.sql.parser.ParserException: syntax error
  • java.sql.SQLRecoverableException: IO Error: Connection reset
  • Error: globalconfigutils setmetadata fail! Cause:java.sql.SQLException…
  • MySql 8.x java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
  • Error attempting to get column time from result set. Cause: java.sql.SQLFe
  • java.sql.SQLException : IO error: socket read timed out!

Источник

Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the

There is a problem when adding, deleting, modifying and querying the interface of a table, as shown in figure

Error codes are as follows:

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 'DESCRIBE , CREATE_TIME, CREATED, UPDATE_TIME, UPDATED from renew_rul' at line 3 ; bad SQL grammar []; nested exception is 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 'DESCRIBE , CREATE_TIME, CREATED, UPDATE_TIME, UPDATED from renew_rul' at line 3 

Prompt me that my SQL syntax is abnormal. I have searched the Internet for a long time, but I haven’t found a similar problem. I specially record it,

The database used is MySQL and the database graphical interface Navicat.

The reason for the problem is that description is a keyword, which needs further processing in mybatis, but it’s strange that status should also be a keyword. Why doesn’t it report an error?

Solution: change the description field to des so that it can be compiled.

Read More:

  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
  • Error querying database.Cause:java.sql.SQLSyntaxErrorException:ORA-00911:invalid character
  • An error is reported about import Java. SQL. *; problem
  • This function has none of deterministic, no SQL, or reads SQL data in its error records
  • SQL state [null]; error code [0]; Error; nested exception is java.sql.SQLException: Error] with root
  • Spring data JAP SQL error:17059 SQL State:99999
  • Cause: java.sql.BatchUpdateException: Unknown column ‘xxx‘ in ‘field list‘
  • Hive SQL syntax error and corresponding solutions
  • SQL 2005 remote connection error (provider: SQL network interface, error: 28 – the server does not support the requested protocol
  • SAP SQL error “SQL code: -10692“ occurred while accessing table “ZTXXXX“.
  • DB2 SQL ERROR: SQLCODE=-803, SQLSTATE=23505, SQL
  • Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNot
  • Java 11.0.11 SQL Server connection error
  • java.sql.SQLException: Incorrect string value:
  • com.alibaba.druid.sql.parser.ParserException: syntax error
  • java.sql.SQLRecoverableException: IO Error: Connection reset
  • Error: globalconfigutils setmetadata fail! Cause:java.sql.SQLException…
  • MySql 8.x java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
  • Error attempting to get column time from result set. Cause: java.sql.SQLFe
  • java.sql.SQLException : IO error: socket read timed out!

Источник

Оцените статью