"Connection unsuccessful java.sql.SQLException: General error"Help Please!!!
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Uma_Varadharajan
Posted On:   Tuesday, September 18, 2001 05:51 AM

Deal Record I have a JSP program using a java bean for inserting records from a form into a MSAccess table. I get the error "Connection unsuccessful java.sql.SQLException: General error ", if I try to insert a second record. If I delete the first one and empty the table, the connection is fine and 1 row is inserted. Could someone help please, as I am very desparate? The entry form is very straight forward, so I have omitted it. Code for Bean: import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import java.util.*; import java.text.*; publ   More>>
Deal Record

I have a JSP program using a java bean for inserting records from a form into a MSAccess table. I get the error

			
"Connection unsuccessful java.sql.SQLException: General error ",


if I try to insert a second record.


If I delete the first one and empty the table, the connection is fine and 1 row is inserted. Could someone help please, as I am very desparate? The entry form is very straight forward, so I have omitted it.
Code for Bean:

			
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.text.*;


public class DealLoaderBean {

private String CustomerName;
private String DealerName;
private String dealCode;
private String convertCode;
private String buySell;
private String gbp_buySell;
private double dealAmount;
private double gbpAmount;
private double XRate;
private double CRate;
private int year;
private int month;
private int day;
private double CFXProfit;
private static int dealID;



public DealLoaderBean(){

CustomerName = "";
DealerName="";
dealCode="";
convertCode="";
buySell="";
gbp_buySell="";
dealAmount=0;
gbpAmount=0;
XRate=0;
CRate=0;
year =0;
month=0;
day=0;
CFXProfit=0;
dealID=0;
}
//getters
public String getCustomerName() {
return CustomerName;
}

public String getDealerName() {
return DealerName;
}

public String getdealCode() {
return dealCode;
}

public String getconvertCode() {
return convertCode;
}


public String getbuySell() {
return buySell;
}

public String getgbp_buySell() {
return gbp_buySell;
}

public double getdealAmount() {
return dealAmount;
}
public double getgbpAmount() {
return gbpAmount;
}
public double getXRate() {
return XRate;
}
public double getCRate() {
return CRate;
}
public int getYear() {
return year;
}

public int getMonth(){
return month;
}

public int getDay(){
return day;
}

public double getCFXProfit(){
return CFXProfit;
}

//Setters
public void setCustomerName(String cName) {
CustomerName=cName;
}

public void setDealerName(String dName) {
DealerName=dName;
}
public void setdealCode(String dc) {
dealCode=dc;
}

public void setconvertCode(String cc) {
convertCode=cc;
}
public void setbuySell(String bs) {
buySell=bs;
}
public void setgbp_buySell(String gbs) {
gbp_buySell=gbs;
}
public void setdealAmount(double amt) {
dealAmount=amt;
}

public void setgbpAmount(double gamt) {
gbpAmount=gamt;
}

public void setXRate(double xr) {
XRate = xr;
}
public void setCRate(double cr) {
CRate = cr;
}
public void setYear(int y) {
year=y;
}

public void setMonth(int m){
month = m;
}
public void setDay(int d){
day = d;
}
public void setCFXProfit(double cfx){
CFXProfit =cfx;
}

//calculations

public String valueDate(int d, int m, int y){
Integer dd = new Integer(d);
Integer mm = new Integer(m);
Integer yy = new Integer(y);
return dd.toString()+"/"+mm.toString()+"/"+yy.toString()+" 12:00:00";
}

public String dealDate(){
/*This piece of code to get date/time conforms to access'95 date format*/

Calendar calendar= Calendar.getInstance();
//Date dt1= calendar.getTime();


/*Express hour <10 as 0+hour(i.e 8 will be 08)*/
int hour=calendar.get(Calendar.HOUR_OF_DAY);
Integer hr= new Integer(hour);
String hrstring;
if(hour <10){hrstring="0"+hr.toString();}
else hrstring=hr.toString();

/*0+min*/
int min=calendar.get(Calendar.MINUTE);
Integer mn = new Integer(min);
String minstring;
if(min <10){minstring="0"+mn.toString();}
else minstring=mn.toString();

/*0+sec*/
int sec=calendar.get(Calendar.SECOND);
Integer sc= new Integer(sec);
String secstring;
if(sec <10){secstring="0"+sc.toString();}
else secstring=sc.toString();
String timestring= hrstring+":"+minstring+":"+secstring;

int day=calendar.get(Calendar.DATE);
Integer dt =new Integer(day);
int month = calendar.get(Calendar.MONTH)+1;
Integer mon =new Integer(month);
int year =calendar.get(Calendar.YEAR);
Integer yr = new Integer(year);
/*Access format date*/
String todayDate = dt.toString()+"/"+mon.toString()+"/"+yr.toString()+" "+timestring;
return todayDate;

}

public int dealID()
{dealID++;
return dealID;
}

//insert
public String insertDeal() {
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection C = DriverManager.getConnection( "jdbc:odbc:BakeryBook");

Statement Stmt = C.createStatement();

String insertion = "INSERT INTO Deals (customerName, dealerName,dealCode,convertCode,buySell,gbp_buySell,exchangeRate,coverRate,dealAmount,gbpAmount,dealDate,valueDate,CFXProfit) VALUES ('"+this.getCustomerName() + "','"+this.getDealerName() + "','" + this.getdealCode() + "','"+ this.getconvertCode() + "','"+this.getbuySell()+"','"+this.getgbp_buySell()+"','"+ this.getdealAmount()+"','"+this.getgbpAmount()+"','"+this.getXRate()+"','"+this.getCRate()+"','"+this.dealDate()+"','"+this.valueDate(this.getDay(),this.getMonth(), this.getYear())+"','"+this.getCFXProfit()+"')";

int stmtInt = Stmt.executeUpdate(insertion);

Stmt.close();
insertion=" ";
C.close();
return "
Inserted row " + stmtInt;

}
catch ( ClassNotFoundException cnfex ) {
// process ClassNotFoundExceptions here
cnfex.printStackTrace();
return( "
Class Not Found
" +
cnfex.toString() );
}
catch ( SQLException sqlex ) {
// process SQLExceptions here
sqlex.printStackTrace();
return( "
Connection unsuccessful
" +
sqlex.toString() );
}
catch ( Exception excp ) {
// process remaining Exceptions here
excp.printStackTrace();
return( excp.toString() );
}
}
}

Code for JSP:
			













The following record was entered:

Customer Name: <%=dlBean.getCustomerName()%>
<% dlBean.setCustomerName(dlBean.getCustomerName());%>

Dealer Name: <%=dlBean.getDealerName()%>
<% dlBean.setDealerName(dlBean.getDealerName());%>

Buy/Sell: <%=dlBean.getbuySell()%>
<% dlBean.setbuySell(dlBean.getbuySell()); %>

GBP Buy/Sell: <%=dlBean.getgbp_buySell()%>
<% dlBean.setgbp_buySell(dlBean.getgbp_buySell()); %>

Currency Code(from): <%=dlBean.getdealCode()%>
<% dlBean.setdealCode(dlBean.getdealCode()); %>

Currency Amount: <%=dlBean.getdealAmount()%>
<% dlBean.setdealAmount(dlBean.getdealAmount()); %>

Currency Code(to): <%=dlBean.getconvertCode()%>
<% dlBean.setconvertCode(dlBean.getconvertCode()); %>

Buy/Sell: <%=dlBean.getbuySell()%>
<% dlBean.setbuySell(dlBean.getbuySell()); %>

GBP Buy/Sell: <%=dlBean.getgbp_buySell()%>
<% dlBean.setgbp_buySell(dlBean.getgbp_buySell()); %>

GBP Amount: <%=dlBean.getgbpAmount()%>
<% dlBean.setgbpAmount(dlBean.getgbpAmount()); %>

Exchange Rate: <%=dlBean.getXRate()%>
<% dlBean.setXRate(dlBean.getXRate()); %>

Cover Rate: <%=dlBean.getCRate()%>
<% dlBean.setCRate(dlBean.getCRate()); %>

Deal Date: <%=dlBean.dealDate()%>
<% dlBean.dealDate();%>

Value Date: <%=dlBean.valueDate(dlBean.getDay(),dlBean.getMonth(),dlBean.getYear())%>
<% dlBean.valueDate(dlBean.getDay(),dlBean.getMonth(),dlBean.getYear());%>

CFX Profit: <%=dlBean.getCFXProfit()%>
<% dlBean.setCFXProfit(dlBean.getCFXProfit()); %>
<% out.print(dlBean.insertDeal()); %>




I used various jguru forum messages to rectify this, but I have been very unsuccessful!
Thanks for your attention

   <<Less
About | Sitemap | Contact