Class DBBean

java.lang.Object
  |
  +--DBBean

public class DBBean
extends java.lang.Object

DBBean - Database bean

a Javabean to perform queries on a JDBC Database, or excute any other SQL statement

Usage:

   DBean bean = new DBBean();
 // setting user and passwd 
  bean.setUserAndPasswd("bla","bla");
  try 
  {
    bean.setConnection("jdbc:fmpro:http://localhost");
    Vector names=bean.getTableNames();
    Vector[] result=bean.getQueryData(names.get(0).toString());
  // print results to screen
     for(int i=0;i<result[1].size();++i)
     {
       //print Header
       System.out.print(" "+result[1].get(i));
     }
  System.out.println();
  for(int j=0;j<result[0].size();++j)
  {
     Vector row=(Vector)result[0].get(j);
     //print rows
     for(int k=0;k<row.size();++k)
     System.out.print(" "+row.get(k));
     System.out.println();
  }
 } catch(Exception e) 
   {
     System.out.println("Error while connecting to database"+ e);
   }
 


Field Summary
 int maxHits
           
 
Constructor Summary
DBBean()
          Constructs a database bean
DBBean(java.lang.String jdbcConnectionURL)
          Constructs a database bean and tries to connect to database specified in the jdbcConnectionURL
 
Method Summary
 java.util.Vector getColumnNames()
           
 java.sql.Connection getConnection()
          returns the Connection if null creates a new one from the url property.
 java.util.Vector getLayoutNames(java.lang.String tableName)
          returns a Vector containing the layoutNames for the specified Table if the database supports this otherwise Vector containing an empty String
 int getMaxHits()
          gets the maximum number of hits
 java.util.Vector getNextRow()
           
 java.util.Vector[] getQueryData(java.lang.String table)
          Returns the result for select * from table with maxHits = 500 default value
 java.util.Vector[] getQueryData(java.lang.String query, int maxHits)
          Returns the result of the query or an Vector array of Vectors containing error messages
 java.util.Vector getTableNames()
          returns a Vector containing the Tablenames or an error message in the Vector
 java.sql.ResultSet makeQuery(java.lang.String query, int numberOfHits)
          makes the database Query with the numberOfHits as maximum
 void setConnection(java.lang.String url)
          sets the connection of this DBBean to the database specified in the url property
 void setConnection(java.lang.String url, java.lang.String user, java.lang.String passwd)
          sets the connection of this DBBean to the database specified in the url and the url,user and passwd property of this DBBean instance
 void setMaxHits(int maxHits)
          sets the maximum number of hits
 void setPasswd(java.lang.String passwd)
          sets the database passwd
 void setURL(java.lang.String url)
          just sets the connection URL
 void setUser(java.lang.String user)
          sets the database user
 void setUserAndPasswd(java.lang.String user, java.lang.String passwd)
          sets the database user and passwd
 java.util.Vector[] TestDB(java.sql.DatabaseMetaData d)
          Test the database drivers features given by the DatabaseMetaData object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxHits

public int maxHits
Constructor Detail

DBBean

public DBBean()
Constructs a database bean

DBBean

public DBBean(java.lang.String jdbcConnectionURL)
       throws java.lang.Exception
Constructs a database bean and tries to connect to database specified in the jdbcConnectionURL
Parameters:
jdbcConnectionURL - url to connect to database
Method Detail

setMaxHits

public void setMaxHits(int maxHits)
sets the maximum number of hits

getMaxHits

public int getMaxHits()
gets the maximum number of hits

getConnection

public java.sql.Connection getConnection()
                                  throws java.lang.Exception
returns the Connection if null creates a new one from the url property.

setConnection

public void setConnection(java.lang.String url)
                   throws java.lang.Exception
sets the connection of this DBBean to the database specified in the url property

setConnection

public void setConnection(java.lang.String url,
                          java.lang.String user,
                          java.lang.String passwd)
                   throws java.lang.Exception
sets the connection of this DBBean to the database specified in the url and the url,user and passwd property of this DBBean instance

getTableNames

public java.util.Vector getTableNames()
returns a Vector containing the Tablenames or an error message in the Vector

getLayoutNames

public java.util.Vector getLayoutNames(java.lang.String tableName)
                                throws java.sql.SQLException
returns a Vector containing the layoutNames for the specified Table if the database supports this otherwise Vector containing an empty String

getQueryData

public java.util.Vector[] getQueryData(java.lang.String table)
                                throws java.sql.SQLException
Returns the result for select * from table with maxHits = 500 default value

getQueryData

public java.util.Vector[] getQueryData(java.lang.String query,
                                       int maxHits)
                                throws java.sql.SQLException
Returns the result of the query or an Vector array of Vectors containing error messages

getColumnNames

public java.util.Vector getColumnNames()

makeQuery

public java.sql.ResultSet makeQuery(java.lang.String query,
                                    int numberOfHits)
                             throws java.sql.SQLException
makes the database Query with the numberOfHits as maximum
Returns:
the result as an ResultSet object

setUser

public void setUser(java.lang.String user)
sets the database user

setPasswd

public void setPasswd(java.lang.String passwd)
sets the database passwd

setUserAndPasswd

public void setUserAndPasswd(java.lang.String user,
                             java.lang.String passwd)
sets the database user and passwd

setURL

public void setURL(java.lang.String url)
just sets the connection URL

TestDB

public java.util.Vector[] TestDB(java.sql.DatabaseMetaData d)
                          throws java.sql.SQLException
Test the database drivers features given by the DatabaseMetaData object

getNextRow

public java.util.Vector getNextRow()
                            throws java.lang.Exception