Saturday, December 29, 2018

JDBC: is an acronym for 'Java Data Base Connectivity'. It is used for accessing the databases from Java Applications. JDBC API allows to do CRUD operations on Database.
Steps to connectivity between Java program and Database:

  1. Loading the Driver
  2. Create the Connections
  3. Create a Statement
  4. Execute the Query
  5. Close the Connections.
Loading the Driver:
We can register the driver using Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName() load the driver's class file into memory, which automatically registers it.
In JDBC API, we have java.sql.Driver, it is only an interface and it is available in JDK.
Create the Connections:
We can establish the connection using
Connection conn=DriverManager.getConnection(String url, String user, String password);
url can be created as "jdbc:oracle:thin:@hostname:port Number:databaseName"

Create a Statement: Interface define the methods and properties that enable you to send SQL or PL/SQL commands and receive data from your database.
Statement st = con.createStatement();

Execute the Query: Reads data from a database query and returns the data in a result set. The java.sql.ResultSet interface represents the result set of a database query.
ResultSet rs=stmt.executeQuery("select query);
Close the Connections:
The close() method of Connection interface is used to close the connection.
conn.close()

Related Posts:

  • foreach() method in Java Java API provides foreach() method since jdk1.8v. This method traverses each element of the collection until all elements have been Processed by the method or an exception is raised. Exceptions thrown by the Operation are pa… Read More
  • Explain public static void main(String[] args){} public static void main(String[] args){} or public static void main(String... args){}: Java main method is the entry point of any java program. Its syntax is always "public static void main(String[] args)". You can only… Read More
  • 2nd highest salary of an employee? MySQL: Sub queries in SQL are great tool for this kind of scenario, here we first select maximum salary and then another maximum excluding result of subquery mysql> SELECT max(salary) FROM Employee WHERE salary NOT IN (S… Read More
  • Fibonacci Series Write a Java Program to print Fibonacci  series up to 10        public class Fibonacci { public static void main(String[] args) { int num = 10;  … Read More
  • HashMap vs ConcurrentHashMap Difference between HashMap and ConcurrentHashMap: ConcurrentHashMap is thread-safe that is the code can be accessed by single thread at a time. while HashMap is not thread-safe HashMap can be synchronized by using sy… Read More

0 comments:

Post a Comment

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts