Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

prob in using SQL Server through JDBC

  Asked By: Nicole    Date: Feb 20    Category: Java    Views: 1115
  

I m facing problem in this code. I m using WebLogic. Whenever i execute this
code, Server response with error Recordset is closed. what is happening i cannt
understand.
can u help me.

ResultSet ts = null;
String excode="";
String seg="";
String Company="";
Statement st = null;
Statement st1 = null;
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
con = DriverManager.getConnection("jdbc:odbc:backoffice","sa","du");
st = con.createStatement();
st1 = con.createStatement();
if (UserCode.equals("NSE6378")) Company="Bonanza Portfolio Ltd";
else if (UserCode.equals("BSE235")) Company="Bonanza Stock Brokers Ltd";
else Company="Bonanza Group";
out.println("<h3 align=center>"+Company.toUpperCase()+"</h3>");
SQL="select count(*) Knt from backoffice..tblSettlements where
Segment<>'Derivative' and SettlementNo='" + SettlementNo + "'";
ts=st.executeQuery(SQL);
if(ts!=null)
{
while(ts.next())
{
int knt = ts.getInt("Knt");
if (knt==0 ){
out.println("<h5>No Such Settlement Found for Cash Segment!!</h5>");
return;
}
}
}
ts.close();
SQL="exec backoffice..getM2mccf '"+ UserCode +"' ,'"+ Login +"' ,'"+
SettlementNo +"','" + Types +"','" + Code + "','" + NDScrip +"'";
out.println("<h5>Mark to Market for Settlement No- " +
SettlementNo.toUpperCase() + "</h5>");
ts=st.executeQuery(SQL);

int DATA_FOUND=0;
if(ts!=null){
out.println("<Table border=1 cellspacing=0 cellpading=0>");
while(ts.next())
{
CurrClientCode=ts.getString("ClientCode");
Name=ts.getString("FullName");
String SaleQty=ts.getString("SaleQty");
double SaleValue=ts.getDouble("SaleValue");
String BuyQty=ts.getString("BuyQty");
double BuyValue=ts.getDouble("BuyValue");
String NetQty=ts.getString("NetQty");
double NetValue=ts.getDouble("NetValue");
String ActualClosingValue=ts.getString("ActualClosingValue");
String AvgRate=ts.getString("AvgRate");
Scrip=ts.getString("ScripName");
String ActualClosingRate=ts.getString("ActualClosingRate");
String NetDiff=ts.getString("NetDiff");

if (PrevClientCode.equals(""))
{
%><tr><th BGCOLOR=lightBlue colspan=11><%
out.println(CurrClientCode+" - "+Name+HEADER);
Code=CurrClientCode;
}
else
{
if (PrevClientCode.equals(CurrClientCode) ){
file://Code=" ";
file://Name=" ";
file://Code=PrevClientCode;
}else{
Code=CurrClientCode;
%><tr><td colspan=11> </td></tr><tr><th BGCOLOR=lightBlue
colspan=11><%
out.println(CurrClientCode+" - "+Name+HEADER);
}
}
if (Scrip.equals("ZZZZZZZZZZZZZZZ"))
{
out.print("<BR>InScript...<BR>");
/*author : Umashankar Yadav
Date : 23rd April 2004
Purpose : in order to include the charge amount in buy value and
subtracting that from sale value a net value will be displayed
only when the total is showing for the particular client this will be
included
*/
ResultSet rst=null;
double tot=0.0;
file://SQL="exec backoffice..getChargeAmount '"+ SettlementNo +"' ,'"+
CurrClientCode +"'";
file://SQL="exec backoffice..getClientCharge '"+ UserCode +"' ,'"+
SettlementNo +"' ,'"+ Code +"'";
SQL="exec backoffice..getClientCharge '"+ UserCode +"' ,'"+ SettlementNo +"'
,'"+ CurrClientCode +"'";
rst=st1.executeQuery(SQL);
if(rst!=null)
{
rst.next();
tot = rst.getDouble(1);
}
rst.close();
file://tot=2.5;

double bv = BuyValue;
double nv = NetValue;
BuyValue = BuyValue + tot;
NetValue = SaleValue-BuyValue;
if(NetValue<0)
{
out.println("<tr bgcolor=silver><td colspan=3
align=right>"+myFormatt.format(bv)+"</td><td colspan=2
align=right>"+myFormatt.format(SaleValue)+"</td><td colspan=2
align=right>"+myFormatt.format(nv)+"</td><td colspan=3
align=right>"+NetDiff+"</td></tr><tr><td colspan= 5 border=0>Total
Charges Exclusive of Brokerage:  " +myFormatt.format(tot)+"</td><td
colspan = 5 border = 0>Bill Amount <font color=red>  " +
myFormatt.format(NetValue) + " Dr</font></td></tr>");
}
else
{
out.println("<tr bgcolor=silver><td colspan=3
align=right>"+myFormatt.format(bv)+"</td><td colspan=2
align=right>"+myFormatt.format(SaleValue)+"</td><td colspan=2
align=right>"+myFormatt.format(nv)+"</td><td colspan=3
align=right>"+NetDiff+"</td></tr><tr><td colspan = 5 border=0>Total
Charges Exclusive of Brokerage:  " +myFormatt.format(tot)+"</td><td
colspan = 5 border = 0>Bill Amount <font color=blue>  " +
myFormatt.format(NetValue) + " Cr</font></td></tr>");
}
}
else
{
out.print("<BR>OutScrip...<BR>");
out.println("<tr><td nowrap>"+Scrip+"</td><td align=right>"+BuyQty+"</td><td
align=right>"+BuyValue+"</td><td align=right>"+SaleQty+"</td><td
align=right>"+SaleValue+"</td><td align=right>"+NetQty+"</td><td
align=right>"+NetValue+"</td><td align=right>"+AvgRate+"</td><td
align=right>"+ActualClosingRate+"</td><td align=right>"+NetDiff+"</td></tr>");
}
PrevClientCode=CurrClientCode;
DATA_FOUND=1;
}
file://end of while loop
out.println("</tbody></table>");
}
if (DATA_FOUND==0)
out.println("No Trades for this Settlement<br>");
}
catch(SQLException e){
out.println("Error:-"+e.getMessage());
}catch(Exception e){
out.println("Error:-"+e.getMessage());
}
if (con!=null) con.close();
%>

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Isaac Evans     Answered On: Feb 20

It seems you are using the same connection  to
create two statements. I would craete two separate
connections. When you close the statement, that,
usually, closes the connection and the result set
associated with the statement. So, always, close
everything ONLY once you are done...

Also, a couple of suggestions. IF you are
definetely using weblogic  for your deployment
environment, I would suggest using the WebLogic's SQL
Server driver instead of JDBC-ODBC bridge: MUCH more
stable. Also, instead of creating the connection
right away, use weblogic connection pool and a
datasource...

 
Didn't find what you were looking for? Find more on prob in using SQL Server through JDBC Or get search suggestion and latest updates.




Tagged: