java.sql.SQLException occurs in JDBC APIs failure while executing any query. Here trying to drop database schema. which is not exist that’s why server is throwing below exception as output.
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 FacingIssuesOnITDB"<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>); System.out.println("Database drop successfully ...."); } } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (SQLException ex) { ex.printStackTrace(); }
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.SQLException occurs in JDBC APIs failure while executing any query. Here trying to drop database schema. which is not exist that’s why server is throwing below exception as output.
Solutions
Instead of directly running drop sql quey .first check for existence of database/table then execute sql query.
for Example
Drop Database:
drop database if exists FacingIssuesOnITDB
Drop Table:
drop table if exists Students
Issues Solution
For more other JAVA/JDBC issues solution follow link JAVA/JDBC Issues.