JDBC Execute Statement is used to execute SQL Statement, The Execute Statement accept SQL object as parameter and return you the result set from a database. In this Tutorial, the code illustrates an example from JDBC Execute Statement. The driver searches a table in the backend. Incase the we try to create a new table on the name of existing table. The output of code show you an Sql Exception, that table of this name already exist in the database of your backend.
The code include a class JdbcExecuteStatement.The class include a main method. Inside the main method, the list of steps to be carried out Loading a driver by calling a class.forName( ) by passing driver class as argument. Once your driver is loaded, you connect your front end application in java to the backend database.DriverManager.getConnection ( ) : The Driver Manager Class call getConnection ( ),return you an connection object This built a connection between the url and database.con.createStatement ( ) : This provides you an sql object. This is done when you built a connection between Url and database, send sql object to execute the query in the backend database.
st.execute ( ) : This method is used to execute the sql query. This may return you a set of row into your table of database.
If there exists an exception in try block, the catch block subsequently catch and handle the exception.
On execution of the code, the println in program show you an exception indicates that created table already exist in database.JdbcExecuteStatement.java
java.sql.SQLException: Table 'abc' already exists
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.