Database storage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haran22
    New Member
    • May 2007
    • 11

    Database storage

    verify and tell me what runtime error in this pgm

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

    public class screen extends Applet implements ActionListener
    {
    TextField t1,t2,t3;
    Label l1,l2,l3;
    Button b1;




    public void init()
    {
    t1=new TextField();
    t2=new TextField();
    t3=new TextField();
    l1=new Label("Enter A:");
    l2=new Label("Enter B:");
    l3=new Label("Result is:");
    b1=new Button("ok");
    add(l1);
    add(t1);
    add(l2);
    add(t2);
    add(l3);
    add(t3);
    add(b1);
    b1.addActionLis tener(this);
    }
    public void actionPerformed (ActionEvent ae)
    {
    if(ae.getSource ()==b1)
    {
    String a1=t1.getText() ;
    String a2=t2.getText() ;
    System.out.prin tln(a1);
    System.out.prin tln(a2);
    int c=Integer.parse Int(a1)+Integer .parseInt(a2);
    String c1=String.value Of(c);

    t3.setText(c1);
    System.out.prin tln(c);
    try
    {
    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
    Connection conn=DriverMana ger.getConnecti on("jdbc:odbc:b b");
    Statement stmt=conn.creat eStatement();
    stmt.executeUpd ate("Insert into screen values('"+a1+"' ,'"+a2+"')");
    System.out.prin tln("Records are added");
    conn.close();
    stmt.close();
    }
    catch(Exception e)
    {
    System.out.prin tln(e);
    }
    }
    }
    }


    //<applet code="screen" width="400" height="300"></applet>
  • haran22
    New Member
    • May 2007
    • 11

    #2
    i have written an applet pgm in java.

    In this program consists of two textfields and one button. when i click the button the data in the 2 textfields wants to store in a datatbase MsAccess.
    Plz tell what is that run time error.. any one plz do this.

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

    public class screen extends Applet implements ActionListener
    {
    TextField t1,t2,t3;
    Label l1,l2,l3;
    Button b1;



    public void init()
    {
    t1=new TextField();
    t2=new TextField();
    //t3=new TextField();
    l1=new Label("Enter A:");
    l2=new Label("Enter B:");
    //l3=new Label("Result is:");
    b1=new Button("ok");
    add(l1);
    add(t1);
    add(l2);
    add(t2);
    //add(l3);
    //add(t3);
    add(b1);
    b1.addActionLis tener(this);
    }

    public void actionPerformed (ActionEvent ae)
    {
    if(ae.getSource ()==b1)
    {
    String a1=t1.getText() ;
    String a2=t2.getText() ;
    System.out.prin tln(a1);
    System.out.prin tln(a2);
    /*int c=Integer.parse Int(a1)+Integer .parseInt(a2);
    String c1=String.value Of(c);
    t3.setText(c1);
    System.out.prin tln(c);*/
    try
    {
    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
    Connection conn=DriverMana ger.getConnecti on("jdbc:odbc:b b");
    Statement stmt=conn.creat eStatement();
    stmt.executeUpd ate("Insert into screen values('"+a1+"' ,'"+a2+"')");
    System.out.prin tln("Records are added");
    conn.close();
    stmt.close();
    }
    catch(Exception e1)
    {
    System.out.prin tln(e1);
    }
    }
    }
    }



    //<applet code="screen" width="400" height="300"></applet>

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by haran22
      verify and tell me what runtime error in this pgm

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

      public class screen extends Applet implements ActionListener
      {
      TextField t1,t2,t3;
      Label l1,l2,l3;
      Button b1;




      public void init()
      {
      t1=new TextField();
      t2=new TextField();
      t3=new TextField();
      l1=new Label("Enter A:");
      l2=new Label("Enter B:");
      l3=new Label("Result is:");
      b1=new Button("ok");
      add(l1);
      add(t1);
      add(l2);
      add(t2);
      add(l3);
      add(t3);
      add(b1);
      b1.addActionLis tener(this);
      }
      public void actionPerformed (ActionEvent ae)
      {
      if(ae.getSource ()==b1)
      {
      String a1=t1.getText() ;
      String a2=t2.getText() ;
      System.out.prin tln(a1);
      System.out.prin tln(a2);
      int c=Integer.parse Int(a1)+Integer .parseInt(a2);
      String c1=String.value Of(c);

      t3.setText(c1);
      System.out.prin tln(c);
      try
      {
      Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
      Connection conn=DriverMana ger.getConnecti on("jdbc:odbc:b b");
      Statement stmt=conn.creat eStatement();
      stmt.executeUpd ate("Insert into screen values('"+a1+"' ,'"+a2+"')");
      System.out.prin tln("Records are added");
      conn.close();
      stmt.close();
      }
      catch(Exception e)
      {
      System.out.prin tln(e);
      }
      }
      }
      }


      //<applet code="screen" width="400" height="300"></applet>
      What exception are you getting?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        ps. please use code tags each time you need to post code. Do not double post questions.


        Deleted one of your threads and merged two of them.

        Comment

        • haran22
          New Member
          • May 2007
          • 11

          #5
          I am getting the runtime Exception.
          Access denied<java.lan g.RunTimePermis sionaccessClass InPackage.sun.j dbc.odbc>
          This is the exception occuring while running the program

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by haran22
            I am getting the runtime Exception.
            Access denied<java.lan g.RunTimePermis sionaccessClass InPackage.sun.j dbc.odbc>
            This is the exception occuring while running the program
            An applet does not have access to the file system or databases on your computer by default. You need to sign your applet first for it to be granted permission. Google "how to sign java applets".

            Comment

            • haran22
              New Member
              • May 2007
              • 11

              #7
              I didnt find in google search. If any one can plz try that n tell me.. plz plz

              Comment

              Working...