|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--DBBean
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 |
public int maxHits
Constructor Detail |
public DBBean()
public DBBean(java.lang.String jdbcConnectionURL) throws java.lang.Exception
jdbcConnectionURL
- url to connect to databaseMethod Detail |
public void setMaxHits(int maxHits)
public int getMaxHits()
public java.sql.Connection getConnection() throws java.lang.Exception
public void setConnection(java.lang.String url) throws java.lang.Exception
public void setConnection(java.lang.String url, java.lang.String user, java.lang.String passwd) throws java.lang.Exception
public java.util.Vector getTableNames()
public java.util.Vector getLayoutNames(java.lang.String tableName) throws java.sql.SQLException
public java.util.Vector[] getQueryData(java.lang.String table) throws java.sql.SQLException
public java.util.Vector[] getQueryData(java.lang.String query, int maxHits) throws java.sql.SQLException
public java.util.Vector getColumnNames()
public java.sql.ResultSet makeQuery(java.lang.String query, int numberOfHits) throws java.sql.SQLException
public void setUser(java.lang.String user)
public void setPasswd(java.lang.String passwd)
public void setUserAndPasswd(java.lang.String user, java.lang.String passwd)
public void setURL(java.lang.String url)
public java.util.Vector[] TestDB(java.sql.DatabaseMetaData d) throws java.sql.SQLException
public java.util.Vector getNextRow() throws java.lang.Exception
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |