Java
Java
BCA-502
Introduction,
Drivers,
Establishing Connection
Connection Pooling.
2. Datagrams are bundles of information passed between machines. Once the datagram
has been released to its intended target, there is no assurance that it will arrive or even
that someone will be there to catch it.
3. Likewise, when the datagram is received, there is no assurance that it hasn’t been
damaged in transit or that whoever sent it is still there to receive a response and it is
crucial point to note.
Java implements datagrams on top of the UDP (User Datagram Protocol) protocol by using
two classes:
1. DatagramPacket object is the data container.
2. DatagramSocket is the mechanism used to send or receive the DatagramPackets.
1. DatagramPacket(byte data[ ], int size) : It specifies a buffer that will receive data and the size
of a packet. It is used for receiving data over a DatagramSocket.
2. DatagramPacket(byte data[ ], int offset, int size) : It allows you to specify an offset into the
buffer at which data will be stored.
3. DatagramPacket(byte data[ ], int size, InetAddress ipAddress, int port) : It specifies a target
address and port, which are used by a DatagramSocket to determine where the data in the
packet will be sent.
4. DatagramPacket(byte data[ ], int offset, int size, InetAddress ipAddress, int port) : It transmits
packets beginning at the specified offset into the data.
Register the component with the Listener. For registering the component with the Listener, many classes
provide the registration methods. Like:
1. Button
public void addActionListener(ActionListener a){}
2. MenuItem
public void addActionListener(ActionListener a){}
3. TextField
public void addActionListener(ActionListener a){}
public void addTextListener(TextListener a){}
4. TextArea
public void addTextListener(TextListener a){}
5. Checkbox
public void addItemListener(ItemListener a){}
6. Choice
public void addItemListener(ItemListener a){} etc….
OR
2. 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.
3. Connection − This is an interface with all methods for contacting a database. The
connection object represents communication context, i.e., all communication with
database is through connection object only.
String url="jdbc:oracle:thin:@localhost:1521:xe";
String user="system";
String pass="oracle2024";
}
}
Subject: Java Programming & Dynamic Webpage Design
Faculty: Prof. Manoj Kumar Gupta 13
Unit-2: Java Notes
BCA-502 JDBC: Program to INSERT Records into Table
package jdbcPro;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class JdbcConnection {
String url="jdbc:oracle:thin:@localhost:1521:xe";
String user="system";
String pass="oracle2024";
String query = "INSERT INTO customer values(11012, 'RKomal Rani', 'Delhi’)”; //step4 execute query
String url="jdbc:oracle:thin:@localhost:1521:xe";
String user="system";
String pass="oracle2024";
String query = "DELETE from student where roll='111’”; //step4 execute query
String url="jdbc:oracle:thin:@localhost:1521:xe";
String user="system";
String pass="oracle2024";
try{
Class.forName("oracle.jdbc.driver.OracleDriver"); //step1 load the driver class
Connection conn = DriverManager.getConnection(url, user, pass); //step2 create the connection object
Statement stmt=conn.createStatement(); //step3 create the statement objec t
ResultSet rs=stmt.executeQuery("select * from student");//step4 execute query
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+"+rs.getString(3));
THANKS
Subject: Java Programming & Dynamic Webpage Design
Faculty: Prof. Manoj Kumar Gupta 20