0
640views
Programming with JDBC
1 Answer
0
0views
  • JDBC is Java Database Connectivity an API to connect to any database through Java program.

  • It has mainly following class structure:

enter image description here

Driver Manager:

  • This class is used specifically to load and register the required driver for the database management system under consideration.

Connection:

  • This class has methods and properties to establish connection with database.

  • Get connection - method of driver manager is used to create instance of connection class.

  • Three parameters are passed as:

connection string, username and password.

  • If the authentication is proper then an instance of connection class is created otherwise error message is passed.

Statement:

  • Once the connection with database is obtained then methods of this class are used to run DML & DDL queries on database.

  • Create statement ( ) - method is used to create instance of this class.

  • It has two methods to execute the queries:

executeQuery (SQL) - is used to execute SELECT statement on the database.

executeUpdate(CQL) - is used to execute insert, update or delete statements on the database.

  • First method returns an object and second method returns an integer indicating how many rows are affected.

ResultSet.

  • This class is used to navigate among the records returned by the query.

  • Execute Query ( ) method returns an object of the type Result set.

  • It is the snapshot of records returned by query.

  • The main methods are

getstring(index) $\rightarrow$ to read from column.

EOF / BOF $\rightarrow$ End of file/ Beginning of file.

next ( ) $\rightarrow$ to point to next record.

getInt (index) $\rightarrow$ to read from column of type Integer.

Please log in to add an answer.