org.ChinaVO.FITSManager.Util
Class DBOperator

java.lang.Object
  extended by org.ChinaVO.FITSManager.Util.DBOperator

public class DBOperator
extends java.lang.Object

A database operator for the whole application.

Version:
v1.0.0 2009-11-14 11:33:27
Author:
Fany

Constructor Summary
DBOperator()
           
 
Method Summary
static void closeDBConnection()
          close the connection with the database.
 void CloseQuery()
          Close the ResultSet and Statement after you call the Query() method.
static java.lang.Boolean Execute(java.lang.String strSQL)
          Execute a SQL statement.
static java.sql.Connection getDBConnection()
          get the only database connection.
static int getFileID(java.io.File f)
          Query the "file" table, then return the file's id in the "file" table.
static int Insert(java.lang.String strSQL, java.lang.String strTable, java.lang.String col)
          Execute a insert SQL statement and return the id of the newest row.
static int insertFile(java.io.File f, boolean isGetID)
          Insert a file's information into the "file" table, and return it's row id(if you set the isGetID=true).
 java.sql.ResultSet Query(java.lang.String strSQL)
          execute a SQL statement and return the ResultSet.
after you call this method, you have to call the closeQuery to clear the ResultSet and Statement.
 java.sql.ResultSet Query(java.lang.String strSQL, int fetchsize)
           
 java.sql.ResultSet Query2(java.lang.String strSQL)
          execute a SQL statement and return the ResultSet.
after you call this method, you have to call the closeQuery to clear the ResultSet and Statement.
The difference between Query and Query2: when you call Query2,you have to deal with the SQLException yourself
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBOperator

public DBOperator()
Method Detail

getDBConnection

public static java.sql.Connection getDBConnection()
get the only database connection.

Returns:
the only connection to the database.

closeDBConnection

public static void closeDBConnection()
close the connection with the database.


Query

public java.sql.ResultSet Query(java.lang.String strSQL)
execute a SQL statement and return the ResultSet.
after you call this method, you have to call the closeQuery to clear the ResultSet and Statement.

Parameters:
strSQL - a SQL statement string.
Returns:
the ResultSet from DBMS.

Query2

public java.sql.ResultSet Query2(java.lang.String strSQL)
                          throws java.sql.SQLException
execute a SQL statement and return the ResultSet.
after you call this method, you have to call the closeQuery to clear the ResultSet and Statement.
The difference between Query and Query2: when you call Query2,you have to deal with the SQLException yourself

Parameters:
strSQL - a SQL statement string.
Returns:
the ResultSet from DBMS.
Throws:
java.sql.SQLException

Query

public java.sql.ResultSet Query(java.lang.String strSQL,
                                int fetchsize)

CloseQuery

public void CloseQuery()
Close the ResultSet and Statement after you call the Query() method.


Execute

public static java.lang.Boolean Execute(java.lang.String strSQL)
Execute a SQL statement.

Parameters:
strSQL - a SQL statement string.
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results

Insert

public static int Insert(java.lang.String strSQL,
                         java.lang.String strTable,
                         java.lang.String col)
Execute a insert SQL statement and return the id of the newest row.

Parameters:
strSQL - an insert SQL statement
strTable - the name of the table you insert data into.
col - the auto increase column's name in the table.
Returns:
the id of the newest row.

getFileID

public static int getFileID(java.io.File f)
Query the "file" table, then return the file's id in the "file" table.

Parameters:
f - a file instance
Returns:
the id of the file, if it's not exists return -1.

insertFile

public static int insertFile(java.io.File f,
                             boolean isGetID)
Insert a file's information into the "file" table, and return it's row id(if you set the isGetID=true).

Parameters:
f - a file instance.
isGetID - if you want to get the id of the file, set isGetID=true, else set isGetID=false.
Returns:
return the file's id(if you set isGetID=true), or -1.