applet using JDBC
why my applet cannot function..
because i'm using MS access to connect to database..
help me to make my program work..
[131 byte] By [
vatos] at [2007-11-11 8:50:12]

# 2 Re: applet using JDBC
i'm doing my assignment using application first..and it is work..but when i converted the application to applet, it does not work..
the data i selected from specifed id cannot be displayed on the applet...
the applet also save the data to the database..
public void actionPerformed(ActionEvent e){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:staff");
Statement stmt = conn.createStatement();
ResultSet rs;
stfIds =Double.parseDouble(textType[1].getText());
if(e.getSource()==btnGo){
rs = stmt.executeQuery("select * from staff1 where sstaffno = " + stfIds +" ");
while(rs.next()){
stfName = rs.getString(3);
stfDpmt = rs.getString(5);
}
if(stfName!=null){textType[0].setText(stfName); textType[4].setText(stfDpmt);}
if(stfName==null)
{ textType[0].setText("");
textType[4].setText("");
textType[1].setText(stfIds +" is not in database,please re-enter"); } stmt.close();conn.close();
}
}catch(ClassNotFoundException cnfe){
System.out.println(cnfe);
}catch(SQLException sqle){
System.out.println(sqle);}
if(rBtn[0].isSelected()){for(int i=0;i<20;i++){rmTxt[i].setText("0.55);
} type = 1}
if(rBtn[1].isSelected()){for(int i=0;i<20;i++){
rmTxt[i].setText("0.30");}type = 2;}
if(e.getSource()==btn[0]){
km = new int[22];id = Integer.parseInt(textType[1].getText());
name = textType[0].getText();
if(type==1){
for(int i=0;i<22;i++){
km[i] = Integer.parseInt(kmTxt[i].getText());
Staff sCar = new StaffCar(name,id,km[i]);
Double tot = sCar.calcClaim();
jumlahTxt[i].setText(Double.toString(tot)); }}
else if(type==2){
id = Integer.parseInt(textType[1].getText());
name = textType[0].getText();
for(int i=0;i<22;i++){
km[i] = Integer.parseInt(kmTxt[i].getText());
Staff sMotor = new StaffMotor(name,id,km[i]);
Double tot = sMotor.calcClaim();
jumlahTxt[i].setText(Double.toString(tot));}}
totalKm = 0; totalAll =0;
for(int i=0;i<22;i++){
totalKm += Double.parseDouble(kmTxt[i].getText());
totalAll += Double.parseDouble(jumlahTxt[i].getText()); }
total[0].setText(Double.toString(totalKm));
total[1].setText(Double.toString(totalAll));//total for jumlah }
if(e.getSource()==btn[1]){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:staff");
Statement stmt = conn.createStatement();
ResultSet rs;
sname = textType[0].getText();
sbahagian = textType[4].getText();
sbulan = textType[3].getText();
sstaffno = Double.parseDouble(textType[1].getText());
sclaim = Double.parseDouble(total[1].getText());
stmt.executeUpdate("insert into claim values ("+sstaffno+",'"+sname+ "','"+sbahagian+"','"+sbulan+"',"+sclaim+")");
stmt.close();conn.close();
}catch(ClassNotFoundException cnfe){
System.out.println(cnfe);
}catch(SQLException sqle){
System.out.println(sqle); } }
public void reset(){
for(int j=0;j<22;j++){
tarikhTxt[j].setText("dd/mm/yy");
jenisTgsTxt[j].setText(" ");
penggunaTxt[j].setText(" ");
kmTxt[j].setText("0");
rmTxt[j].setText(" ");
jumlahTxt[j].setText(" ");
mulaTxt[j].setText(" ");
sampaiTxt[j].setText(" ");
dariTxt[j].setText(" ");
keTxt[j].setText(" ");
total[j].setText(" ");}
for(int i=0;i<5;i++){textType[i].setText(" "); }
}
public boolean validation(){
for(int i=0;i<5;i++){
if(textType[i].equals(" "))
return false;}
return true;}
public void init(){MyApplet my = new MyApplet();} }
vatos at 2007-11-11 22:35:17 >
