so do u feel there is error in DBtransaction
here is code
package infiniteopps.db.local;
import java.sql.*;
import java.util.*;
public class DBTransaction
{
String strfldList,strfldVal;
//This two varirable is use to hold the filed list and field value for insert
Statement
String strSetUpd,strSetCond;
//strSetUpd varirable is use to hold the filed list and field value for Update
Statement
//strSetCond is use to hold where clause for update and delete Statement
String sql;
//sql variable is use to collect and make a sql queary for insert,update and
Delete Statement
String tblNm;
//tblName Holds The table name for the for update and delete Statement
//PoolManager poolMgr;
//poolMgr is object for geting instance to the connection object
String strShowSQL;
public Connection Con;
/*
DBTran constructor is use to set the PoolManger class instance and set the initial
values for the variables
*/
public DBTransaction()
{
strfldList="";
strfldVal="";
strSetCond="";
strSetUpd="";
tblNm="";
sql="";
try
{
/*
String url = "jdbc:inetdae7:64.164.13.156"; //
use your hostname and port number
String login = "iisinfi"; //
use your login here
String password = "infi1348iis";
// use your password here
DriverManager.setLogStream(System.out); // to create more
info
Class.forName("com.inet.tds.TdsDriver").newInstance(); //
JDK,Netscape,IE
DriverManager.setLoginTimeout(10); //set a timeout for
login and query
Con=
DriverManager.getConnection(url,login,password);//open a connection to the database
Con.setCatalog("iisinfi"); //select a database
*/
//String url= "jdbc:AvenirDriver://server1:1433/infinitebu";
//String url=
"jdbc:AvenirDriver://203.199.134.20:1433/infiniteopps";
//Con= DriverManager.getConnection(url,"infiniteopps","changed00");
//String url= "jdbc:AvenirDriver://server1:1433/infinitebu";
Class.forName ("net.avenir.jdbc2.Driver"); //Registering the
Driver
String url= "jdbc:AvenirDriver://server1:1433/infiniteopps";
Con= DriverManager.getConnection(url,"sa","");
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
// poolMgr = PoolManager.getInstance();
}
public Connection getConnection()
{
return Con;
}
/*
setTable() Method set the table name for the value
*/
public void setTable(String strTbl)
{
tblNm=strTbl;
}
/*
setWhere() method is use to set the where condition having two parameter field name
and it's value
for update and delete statement
*/
public void setWhere(String fldNm,String fldVal)
{
if ((strSetCond.trim()).length()>0 )
strSetCond = strSetCond + " and " + fldNm + " = " + "'" + fldVal
+"'";
else
strSetCond = strSetCond + fldNm + " = " + "'" + fldVal +"'";
}
public void setWhere(String fldNm,int fldVal)
{
if ((strSetCond.trim()).length()>0 )
strSetCond = strSetCond + " and " + fldNm + " = " + "" +
fldVal +"";
else
strSetCond = strSetCond + fldNm + " = " + "" + fldVal +"";
}
public void setWhere(String fldNm,float fldVal)
{
if ((strSetCond.trim()).length()>0 )
strSetCond = strSetCond + " and " + fldNm + " = " + "" + fldVal
+"";
else
strSetCond = strSetCond + fldNm + " = " + "" + fldVal +"";
}
/*
delete() method is use to execute the delete queary
*/
public void delete() throws SQLException
{
try
{
sql = "Delete from " + tblNm + " Where " + strSetCond ;
strShowSQL = sql;
PreparedStatement stat = Con.prepareStatement(sql);
stat.executeUpdate();
stat.close();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("delete() finally");
//poolMgr.release();
}
strfldList="";
strfldVal="";
strSetCond="";
strSetUpd="";
tblNm="";
}
/* this is to truncate the table
public void truncate() throws SQLException
{
try
{
sql = "Truncate from " + tblNm + " Where " + strSetCond ;
strShowSQL = sql;
PreparedStatement stat = Con.prepareStatement(sql);
stat.executeUpdate();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("delete() finally");
//poolMgr.release();
}
strfldList="";
strfldVal="";
strSetCond="";
strSetUpd="";
tblNm="";
}
*/
public void executeQuery(String sql)throws SQLException
{
try
{
strShowSQL = sql;
PreparedStatement stat = Con.prepareStatement(sql);
stat.executeUpdate();
stat.close();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("executeQuery() finally");
//poolMgr.release();
}
strfldList="";
strfldVal="";
strSetCond="";
strSetUpd="";
tblNm="";
}
/*
update() method is use to execute the Update queary
*/
public void update()throws SQLException
{
try
{
sql = "update " + tblNm + " set " + strSetUpd + " Where " +
strSetCond ;
strShowSQL = sql;
PreparedStatement stat = Con.prepareStatement(sql);
stat.executeUpdate();
stat.close();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("update() finally");
//poolMgr.release();
}
strfldList="";
strfldVal="";
strSetCond="";
strSetUpd="";
tblNm="";
}
/*
setFields() method is use to set the field name and corresponding value
*/
public void setFields(String fldNm,String fldVal)
{
strfldList=strfldList + fldNm +",";
strfldVal=strfldVal + "'" + fldVal + "',";
if ((strSetUpd.trim()).length()>0 )
strSetUpd= strSetUpd + " , " + fldNm + " = " + "'" + fldVal
+"'";
else
strSetUpd = strSetUpd + fldNm + " = " + "'" + fldVal +"'";
}
public void setFields(String fldNm,int fldVal)
{
strfldList=strfldList + fldNm+",";
strfldVal=strfldVal + "" + fldVal + ",";
if ((strSetUpd.trim()).length()>0 )
strSetUpd= strSetUpd + " , " + fldNm + " = " + "" + fldVal +"";
else
strSetUpd = strSetUpd + fldNm + " = " + "" + fldVal +"";
}
public void setFields(String fldNm,float fldVal)
{
strfldList=strfldList + fldNm+",";
strfldVal=strfldVal + "" + fldVal + ",";
if ((strSetUpd.trim()).length()>0 )
strSetUpd= strSetUpd + " , " + fldNm + " = " + "" + fldVal
+"";
else
strSetUpd = strSetUpd + fldNm + " = " + "" + fldVal +"";
}
/*
save() method for executing the insert into queary
*/
public void save()
{
strfldList= strfldList.substring(0,strfldList.lastIndexOf(","));
strfldVal= strfldVal.substring(0,strfldVal.lastIndexOf(","));
sql=sql="insert into " + tblNm + " " + "(" + strfldList + ") " + "
values(" + strfldVal + ")";
strShowSQL = sql;
//System.out.println(strShowSQL);
try
{
PreparedStatement stat = Con.prepareStatement(sql);
stat.executeUpdate();
stat.close();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("save() finally");
//poolMgr.release();
}
strfldList="";
strfldVal="";
strSetUpd="";
sql="";
}
/*
getResult is a functon use to execute a queaary and return the
result set with out parameter and this function has one parameter is required ie
a SQL Select Sataement
*/
public ResultSet getResult(String sql)
{
ResultSet r = null;
Statement s = null;
try
{
strShowSQL = sql;
s = Con.createStatement();
r = s.executeQuery(sql);
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
try{
//s.close();
}catch(Exception e){}
//System.out.println("getResult() finally");
//poolMgr.release();
}
return r;
}
/*
getPreResult is a functon use to execute a queaary and return the
result set with parameters and this function has one parameter is required ie
a SQL Select Sataement
*/
public ResultSet getPreResult(String sql)
{
ResultSet r = null;
PreparedStatement ps = null;
try
{
strShowSQL = sql;
ps = Con.prepareStatement(sql);
r = ps.executeQuery();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("getPreResult() finally");
//poolMgr.release();
}
return r;
}
public int getNextId(String strTblNm,String strFldNm) throws SQLException
{
int id = 0;
try
{
ResultSet rsId = null;
Statement s = null;
String sql = "select max(" + strFldNm + ") from " + strTblNm;
s = Con.createStatement();
rsId = s.executeQuery(sql);
if(rsId.next())
{
id = rsId.getInt(1);
}
rsId.close();
s.close();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("getNextId() : " + sql);
//System.out.println("getNextId() finally");
//poolMgr.release();
}
id++;
return id;
}
public boolean isExist(String strValue,String strFldNm,String strTblNm)
{
boolean flag = true;
try
{
String strSql ="";
strSql = "select " + strFldNm + " from " + strTblNm + " where "
+ strFldNm + "= '" + strValue + "'";
Statement s = null;
ResultSet rs = null;
s = Con.createStatement();
rs= s.executeQuery(strSql);
if (rs.next())
flag = false;
else
flag = true;
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("isExist() finally");
//poolMgr.release();
}
return flag;
}
public void closeConnection()
{
try
{
Con.close();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
}
public boolean isExist(int intValue,String strFldNm,String strTblNm)
{
boolean flag = true;
try
{
String strSql = "";
strSql = "select " + strFldNm + " from " + strTblNm + " where " +
strFldNm + "= " + intValue + "";
Statement s = null;
ResultSet rs = null;
s = Con.createStatement();
rs= s.executeQuery(strSql);
if (!rs.next())
flag = false;
else
flag = true;
rs.close();
s.close();
}
catch(SQLException e)
{
throw new NrcException(e.toString());
}
catch(Exception e)
{
throw new NrcException(e.toString());
}
finally
{
//System.out.println("isExist() finally");
//poolMgr.release();
}
return flag;
}
public String displayQuery()
{
return strShowSQL;
}
public void setAutoCommit(boolean bol)throws SQLException
{
Con.setAutoCommit(bol);
}
public void commit()throws SQLException
{
Con.commit();
}
}
class NrcException extends RuntimeException
{
NrcException()
{}
NrcException(String e)
{
super(e);
}
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html