Professional Documents
Culture Documents
in
DriverManager: This class manages a list of database drivers. Matches connection requests from the
java application with the proper database driver using communication sub protocol. The first driver
that recognizes a certain subprotocol under JDBC will be used to establish a database Connection.
Driver: This interface handles the communications with the database server. You will interact directly
with Driver objects very rarely. Instead, you use DriverManager objects, which manages objects of this
type. It also abstracts the details associated with working with Driver objects.
Connection: The connection object represents communication context, i.e., all communication with
database is through connection object only.
Statement: Object of this class is used to submit the SQL statements to the database.
ResultSet: These objects hold data retrieved from a database after you execute an SQL query.
SQLException: This class handles any errors that occur in a database application.
try and catch – both of these are used for error handling or exception handling which is necessary in
java.
o try block – in this block we write all of the statements that are prone to error.
import java.sql.* - import all of the sql library classes in the current program.
jdbc:mysql://localhost:3306/infotech","root", "123456"
rs.next() – next method of ResultSet class is used to move to the next record of resultset.
Insert Update
try try
{ {
Class.forName("java.sql.Driver"); Class.forName("java.sql.Driver");
} }
catch(Exception e) catch(Exception e)
{ {
System.out.println(e); System.out.println(e);
} }
try
try {
{ Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:330
Connection con =
6/juhi","root", "123456");
DriverManager.getConnection("jdbc:mysql://localhost:330
6/juhi","root", "123456"); int r,m,r1;
String n; r=Integer.parseInt(jtfroll.getText());
r=Integer.parseInt(jtfroll.getText()); n=jtfname.getText();
n=jtfname.getText(); m=Integer.parseInt(jtfmarks.getText());
m=Integer.parseInt(jtfmarks.getText()); r1=Integer.parseInt(jtfsearch.getText());
JOptionPane.showMessageDialog(null,"Record JOptionPane.showMessageDialog(null,"Record
Saved"); Updated");
} catch(Exception e) { } catch(Exception e) {
System.out.println(e); System.out.println(e);
} }
Delete Search
{ try {
Class.forName("java.sql.Driver"); Class.forName("java.sql.Driver");
} }
catch(Exception e) catch(Exception e) {
{ System.out.println(e);
System.out.println(e); }
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:330
try 6/juhi","root", "123456");
{ int r,m,r1;
Connection con = String n;
DriverManager.getConnection("jdbc:mysql://localhost:330
6/juhi","root", "123456"); r1=Integer.parseInt(jtfsearch.getText());
JOptionPane.showMessageDialog(null,"Record jtfroll.setText(""+r);
Deleted");
jtfname.setText(""+n);
jtfmarks.setText(""+m);
} catch(Exception e) {
}
System.out.println(e);
else {
}
JOptionPane.showMessageDialog(null,"Record Not
Found"); }
} catch(Exception e) {
System.out.println(e);