BISLAB
This program shows the coding style to be used
import java.sql.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
//This is an example class to check the JDBC Connectivity with Oracle.
//Module Name : ExampleDemo
public class TestJdbc extends java.applet.Applet {
Button execute_Button;
TextArea output;
//Creates a panel window in the applet area with a button which enables
//to trigger the query.
public void init () {
this.setLayout (new BorderLayout ());
Panel p = new Panel ();
p.setLayout (new FlowLayout (FlowLayout.LEFT));
execute_Button = new Button ("Hello JDBC");
p.add (execute_Button);
this.add ("North", p);
output = new TextArea (10, 60);
this.add ("Center", output);
}
//Captures the Button click event an invokes the ProcessRequest Method;
public boolean action(Event e, Object o) {
if(e.target.equals(execute_Button) ) {
System.out.println("\n Event Captured...");
ProcessRequest();
System.out.println("\n Event Processed...");
return true;
}
else
return false;
}
//Method to make a connection to oracle using JDBC and quering a simple
//table. This method also displays the result of the query to the window
//panel in the applet.
public synchronized void ProcessRequest() {
String username, passwd,query;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println(" \n Checked Forname ");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@everest.cse.iitb.ernet.in:1521:GEN","satish","satish");
System.out.println("Connection over...");
Statement stmt = con.createStatement();
query = "select * from userlist";
ResultSet rs = stmt.executeQuery(query);
System.out.println("\n Query Executed...");
while(rs.next()) {
username = rs.getString(1);
passwd = rs.getString(2);
output.appendText(" "+username +" "+passwd+ " \n");
}
rs.close();
con.close();
}
catch(Exception e) {
output.setText(e.getMessage());
System.out.println("\n Error, Driver Fault...");
System.out.println(e.getMessage());
}
}
}