Write a program in Java for student details (Roll No, Name etc) to Access as a database and write the application in JDBC. (AWT or JFame).

Posted on

Task No 05


AIM:


Write a program in Java that enters pupil particulars (Roll No, Identify and so on) and retrieves information. Use Entry as a database and write the appliance in JDBC. (AWT or JFame)


THEORY:


JDBC stands for Java Database connectivity’s. It’s a software program layer that enables builders to write down actual client-server projects in Java. JDBC is predicated on the X/OPEN name stage interface (CLI) for SQL. JDBC was designed to be a really compact, easy interface specializing in the execution of uncooked SQL statements and retrieving the outcomes. The parts of JDBC are Utility, Driver supervisor and Driver.


JDBC   Vs ODBC


  • ODBC can’t be immediately used with Java as a result of it makes use of a C interface.

  • ODBC makes use of pointers which have been completely faraway from Java.

  • ODBC mixes easy and superior options collectively and has complicated choices for easy queries.

  • ODBC requires handbook set up of the ODBC driver supervisor and driver on all consumer machines. JDBC drivers are written in Java and JDBC code is routinely installable, safe and moveable on all java platforms from community computer systems to mainframes.


The JDBC API defines a set of interfaces and courses for use for communications with a database. These interfaces and courses are discovered within the java.sql package deal. The outcomes of the SQL statements are saved in ResultSet object and getXXX methodology used to retrieve the information from ResultSet. A transaction is about of a number of statements which are executed collectively as a unit, so both all the statements are executed or not one of the assertion is executed.


DSN: Sorts of DSN


  • File DSN  Accessibility may be very low
  • System DSN – Simple to entry and by all customers.
  • Consumer DSN  Particular to a person however not moveable.



Steps for utilizing JDBC:


//step 1- import the java.sql package deal

import java.sql.*;

Class Buyer {

public static void predominant(String arg[ ]) throws SQLException {


//step 2-register the driving force

class.forName (”solar.jdbc.odbc.JdbcOdbcDriver”);


//step 3-connect to a database

Connection c= DriverManager.getConnection(“Jdbc.odbc:DSN”,”username”,”password”);


//step 4- create an announcement

Assertion s = c.createStatement( );


//step 5-execute the assertion

Resultset rs = s.executeQuery (“ SQL assertion”);


s.executeUpdate( ): That is used for all DDL command current in a database (ALTER, DROP, INSERT and CREATE ). This doesn’t returns something however executes the question and replace the database.


s.execute( ): This methodology is used to execute an SQL assertion which will return a number of returns The return worth is a Boolean. Which is true if the following result’s a Resultset and false whether it is an replace rely or there aren’t any extra outcomes.


//step 6- for displaying the column title

ResultSetMetaData rsmd =rs.getMetaData( );

int i =rsmd.getColumnCount( );

for(int j=i; j<=i; j++)

{

System.out.println( rsmd.getColumnName( j)+”t”);

System.out.println(” ”);

}


//step 7-retrieve the outcomes

whereas(rs.subsequent( ) );

{

for(int j=i; j<=i; j++)

{

System.out.println( rs.getString( j)+”t”);

}

System.out.println(” ”);

}


//step 8-close the assertion and connection

s.shut( );

c.shut( );

}

}

A batch replace is a set of a number of replace statements that may be a submitted to the database for processing as a batch. AddBatch, clearBatch and executeBatch are among the strategies which are used for batch updates. Two kinds of exceptions are thrown throughout batch updates they usually embrace SQLException and BatchUpdateException.


 CONCLUSION


JDBC is efficiently applied. 

Supply projectgeek.com