package Permit;
import java.sql.*;
public class DbBean {
private Connection dbCon;
private String dbURL="";
// a default database URL may be provided here.
private String dbDriver="";
// Set the database URL.
public void setDbURL(String dbURL) {
this.dbURL = dbURL;
// Open a database connection
public boolean connect() throws ClassNotFoundException, SQLException {
dbCon = DriverManager.getConnection(this.getDbURL());
return true;
//Close the database connection.
public void close() throws SQLException {
// Executes an SQL Query.
public ResultSet execSQLQuery(String sql) throws SQLException {
Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return r;
An example for a database query with the DbBean class looks like this. In the presented case, a 
list of all company names is extracted from the Company table. 
// Instantiate the database JavaBean class
DbBean dbBean = new DbBean();
// Set the database URL
// Establish a connection
// Execute the SQL query
ResultSet rs = dbBean.execSQLQuery("SELECT ComName FROM Company");
// Now, do something with the result set, e.g. display it!
// Don't forget to close the connection!

Java Web Hosting Application Development Using Java Technologies Hosting Business web hosting division of Vision Web Hosting Inc. All rights reserved.