The Artima Developer Community
Sponsored Link

Java Answers Forum
Run Time Error in my program.

1 reply on 1 page. Most recent reply: Mar 9, 2002 9:55 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
N.Ramchandar

Posts: 1
Nickname: ramchandar
Registered: Mar, 2002

Run Time Error in my program. Posted: Mar 9, 2002 12:52 AM
Reply to this message Reply
Advertisement
Hi.

I am a new comer to Java Programming. I have written an applet program in java using MS-Access Database to store my data. The applet starts fine, but when I click on the update button to get the record inserted into the access database, a runtime is being given.

Could anyone please help me out of this problem. I have java sdk 1.4 on my system installed and platform is windows 98. The program is given below.

Thanks.

N.Ramchandar

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

// <applet code=Sample2 height = 300 width = 400> </applet>

public class Sample2 extends Applet implements ActionListener
{
private Button updateButton;
private TextField itemNbr;
private TextField itemDesc;
private TextField itemQty;
private TextField itemWholesale;
private TextField itemRetail;
private TextField itemCompany;
private TextField itemColor;
private TextField itemSize;
private TextField textResult;

public void init()
{
setBackground(new Color(255,255,255));
setFont(new Font("Helvetica", Font.PLAIN,12));
setLayout(new BorderLayout(5,5));
Panel upperpanel = new Panel();
upperpanel.setLayout(new BorderLayout());
Panel uppertoppanel = new Panel();
uppertoppanel.setLayout(new FlowLayout(1,5,5));

uppertoppanel.add(new Label("Item Nbr :"));
itemNbr = new TextField(" ",5);
uppertoppanel.add(itemNbr);

uppertoppanel.add(new Label("Item Desc :"));
itemDesc = new TextField(" ",25);
uppertoppanel.add(itemDesc);

upperpanel.add("North",uppertoppanel);

Panel upperbotpanel = new Panel();
upperbotpanel.setLayout(new FlowLayout(1,5,5));

upperbotpanel.add(new Label("Item Qty :"));
itemQty = new TextField(" ",3);
upperbotpanel.add(itemQty);

upperbotpanel.add(new Label("Item Wholesale Cost :"));
itemWholesale = new TextField(" ",7);
upperbotpanel.add(itemWholesale);

upperpanel.add("South",upperbotpanel);
add("North",upperpanel);

Panel middlepanel = new Panel();

middlepanel.setLayout(new BorderLayout());
Panel middletoppanel = new Panel();
middletoppanel.setLayout(new FlowLayout(1,5,5));

middletoppanel.add(new Label("Item Retail :"));
itemRetail = new TextField(" ",7);
middletoppanel.add(itemRetail);

middletoppanel.add(new Label("Item Company :"));
itemCompany = new TextField(" ",3);
middletoppanel.add(itemCompany);

middlepanel.add("North",middletoppanel);
Panel middlebotpanel = new Panel();
middlebotpanel.setLayout(new FlowLayout(1,5,5));

middlebotpanel.add(new Label("Item Color :"));
itemColor = new TextField(" ",8);
middlebotpanel.add(itemColor);

middlebotpanel.add(new Label("Item Size :"));
itemSize = new TextField(" ",8);
middlebotpanel.add(itemSize);

middlepanel.add("South",middlebotpanel);

add("Center",middlepanel);
Panel botpanel = new Panel();
botpanel.setLayout(new FlowLayout(1,5,5));

updateButton = new Button(" Update ");
updateButton.addActionListener(this);
botpanel.add(updateButton);

textResult = new TextField(" ",60);
botpanel.add(textResult);
add("South",botpanel);

}

public void actionPerformed(ActionEvent event)
{
if(event.getSource() == updateButton)
{
processRequest();
}
}


private synchronized void processRequest()
{
String stringResult = " ";
String result;
String stringNbr;
String stringDesc;
String stringQty;
String stringWholesale;
String stringRetail;
String stringCompany;
String stringColor;
String stringSize;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc.odbc.RAM";
Connection conn = DriverManager.getConnection(url,"dba","sql");
textResult.setText("Connected ...");
Statement stmt = conn.createStatement();
stringNbr = itemNbr.getText();
stringDesc = itemDesc.getText();
stringQty = itemQty.getText();
stringWholesale = itemWholesale.getText();
stringRetail = itemRetail.getText();
stringCompany = itemCompany.getText();
stringColor = itemColor.getText();
stringSize = itemSize.getText();

String sqlString = "INSERT INTO retail_item(item_nbr,item_desc, " +
"qty_per_pkg,wholesale_cost,retail_cost, " +
"company_id,color,size) " +
"VALUES(stringNbr,stringDesc,stringQty, " +
"stringWholesale,stringRetail,stringCompany, "+
"stringColor,stringSize)";

textResult.setText("Working ....");
stmt.executeUpdate(sqlString);
textResult.setText("Completed .....");
stmt.close();
}

catch(Exception e)
{
textResult.setText(e.getMessage());
}

}
}


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Run Time Error in my program. Posted: Mar 9, 2002 9:55 AM
Reply to this message Reply
I suspect the cause of the runtime error is Security related. The applet would have to be signed to work because of applet security restrictions.

May I suggest that you run your program an an application and use a Frame as your container.
If you have your odbc connection setup, it should run fine from the computer you are running on.
Then at least you can learn all about jdbc programming and not fight the security manager restrictions with applets.

Code signing costs several hundred dollars to get set up.
Most people like me just want to learn to program and don't have the bucks to get a digital certificate from Verisign or Thawte just to do general programming.

Flat View: This topic has 1 reply on 1 page
Topic: Methods Previous Topic   Next Topic Topic: How to add a keylistener to a JPanel

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use