Showing posts with label JDBC. Show all posts
Showing posts with label JDBC. Show all posts

Thursday, 24 January 2019

prepared statement vs callable statement


At the top level you can go by this thought Prepared Statement
Instances of PreparedStatement contain an SQL statement that has already been compiled. This is what makes a statement "prepared"
Because PreparedStatement objects are precompiled, their execution can be faster than that of Statement objects.
The prepared statement is used to execute sql queries Callable Statement
A CallableStatement object provides a way to call stored procedures in a standard way for all RDBMSs. A stored procedure is stored in a database; the call to the stored procedure is what a CallableStatement object contains.

Statement.execute(sql) vs executeUpdate(sql) and executeQuery(sql)

boolean execute(): Executes the SQL statement in this Prepared Statement object, which may be any kind of SQL statement.
ResultSet executeQuery(): Executes the SQL query in this Prepared Statement object and returns the ResultSet object generated by the query.
int executeUpdate(): Executes the SQL statement in this Prepared Statement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.

Tuesday, 22 January 2019

ITV-JDBC-Why we use Class.forName(“oracle.jdbc.driver.OracleDriver”) while connecting to a database?

1)Why we use Class.forName(“oracle.jdbc.driver.OracleDriver”) while connecting to a database?
https://stackoverflow.com/questions/20078586/why-we-use-class-forname-oracle-jdbc-driver-oracledriver-while-connecting-to
  1. Sometimes it is required to load a class during the run time. i.e, any class can be loaded into the memory location dynamically while executing the java application. The Class.forName is used to load any given class (within double quotes as String) at run time. For example, when we use IDE, we see there will be a GUI builder which allows us to drag and drop the buttons, text fields, etc. This drag and drop mechanism internally requires certain classes to be loaded at run time.
  2. In the Class.forName (sun.jdbc.odbc.JdbcOdbcDriver), the Class belongs to the package java.lang.Class and the forName() is a static method of the java.lang.Class. The JDBC Drivers (String) will be loaded into the class dynamically at run time and forName method contains static block which creates the Driver class object and register with the DriverManager Service automatically. Since the forName() is static, we call it using the class name (Class).

40 Latest Interview Questions and Answers on Spring, Spring MVC, and Spring Boot

  40 Latest Interview Questions and Answers on Spring, Spring MVC, and Spring Boot 1. What is Tight Coupling? When a class (ClassA) is depen...