[Introduction]
In order to Execute different queries in java program, we need a Statement that is Interface and represents the SQL query.
In order to Execute different queries in java program, we need a Statement that is Interface and represents the SQL query.
- Interface is part of the java.sql package.
- An object of Connection Interface is used to create a statement.
There are three types of statements.
- Statement-> This Statement is used to implement simple queries like creating a table and other which have no parameter means query of table creation "CREATE TABLE DEMO (ID int)".This is a static query so we can use a Statement to implement it.
- PreparedStatement-> PreparedStatement is used when we need a dynamic query, suppose you created a search box. The value of this box will fetch the details of that. so it is not possible to write a search query for every value. the possible way is to pass a different value in the query.
- CallableStatement-> Used to execute stored procedures(function) that may contain both input and output parameters.
String query = "create table employee(id int, name varchar(20),salary int)"; Statement st = conn.createStatement();
String query = "select * from employee where id=?"; PreparedStatement ps = conn.prepareStatement(query); ps.setInt(1,5);
![]() |
always excited |
[connection code]
February 24, 2020
Tags :
JDBC
Subscribe by Email
Follow Updates Articles from This Blog via Email
No Comments
Please comment here...