N.Ramchandar
Posts: 1
Nickname: ramchandar
Registered: Mar, 2002
Run Time Error in my program.
Posted: Mar 9, 2002 12:52 AM
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()); } } }