Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem With Applet Connecting With Microsoft Access Database

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Location
    Delhi
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem With Applet Connecting With Microsoft Access Database

    I am trying to connect the applet with MS Access database (.accdb) but i am getting Access Permission Errors.

    I tried ODBC dsn , policy tool also but can't get desired results.


    I am submitting my code as well as the error below.
    Any help will be appreciated.

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.sql.*;
    import javax.swing.JOptionPane.*;
    import java.net.*;
    import java.io.*;
     
     
    // <APPLET code="addstudent.class" width=500 height=500> </applet>
     
     
    public class addstudent extends JApplet implements ActionListener
        { JTextField fname,lname,year,month,day,address,phonenumber,enrollmentnumber;
          JButton submit;  
          Image background; 
          Connection con;
          Statement s;
     
     
       /* init() method of applets, that gets executed first*/
         public void init()
             {  
                /*Code to set radar as the background for out main applet window */
     
                   background = getImage(getCodeBase(),"Welcome.gif");
                   setContentPane(new JPanel()
                     {
                        protected void paintComponent(Graphics g)
                           {
                             g.drawImage(background, 0, 0, getSize().width, getSize().height, this);
                           }
                     });
     
               /*Background Set*/      
     
     
     
     
     
              Container contentpane = this.getContentPane();
     
              fname  =  new JTextField(8);
              lname  =  new JTextField(8);
              year   =  new JTextField(4);
              month  =  new JTextField(2);
              day    =  new JTextField(2);
              address = new JTextField(30);
              enrollmentnumber = new JTextField(10);
              phonenumber = new JTextField(10);
              submit = new JButton("Submit");
     
     
              contentpane.setLayout(new GridBagLayout());
              GridBagConstraints constraints = new GridBagConstraints();
     
              constraints.gridx = 0;
              constraints.gridy = 1;
              constraints.weightx = 100;
              constraints.weighty = 100;
              constraints.gridwidth = 1;
              constraints.gridheight = 1;
     
     
              constraints.insets.left = 10;
              constraints.anchor = GridBagConstraints.WEST;
              contentpane.add(new JLabel("First Name"),constraints);
     
              constraints.anchor = GridBagConstraints.WEST;
              constraints.insets.left = 0;
              constraints.gridx = 1;
              constraints.gridy = 1;
              contentpane.add(fname,constraints);
     
              constraints.anchor = GridBagConstraints.CENTER;
              constraints.gridx = 2;
              constraints.gridy = 1;
              contentpane.add(new JLabel("Last Name"),constraints);
     
              constraints.anchor = GridBagConstraints.WEST;
              constraints.gridx = 3;
              constraints.gridy = 1;
              contentpane.add(lname,constraints);
     
     
     
     
     
     
              constraints.anchor = GridBagConstraints.NORTH;
              constraints.gridx = 0;
              constraints.gridy = 2;
              contentpane.add(new JLabel("Date of Birth: "),constraints);
     
              constraints.anchor = GridBagConstraints.NORTHWEST;
              constraints.gridx = 1;
              constraints.gridy = 2;
              contentpane.add(day,constraints);
     
              constraints.anchor = GridBagConstraints.NORTHWEST;
              constraints.gridx = 1;
              constraints.gridy = 2;
              constraints.insets.left = 30;
              contentpane.add(new JLabel("day"),constraints);
     
              constraints.anchor = GridBagConstraints.NORTH;
              constraints.gridx = 1;
              constraints.gridy = 2;        
              //constraints.insets.left = 30;
              contentpane.add(month,constraints);
     
              constraints.anchor = GridBagConstraints.NORTH;
              constraints.gridx = 1;
              constraints.gridy = 2;
              constraints.insets.left = 100;      
              contentpane.add(new JLabel("month"),constraints);
     
              constraints.anchor = GridBagConstraints.NORTHWEST;
              constraints.gridx = 2;
              constraints.gridy = 2;
              constraints.insets.left = 0;
              contentpane.add(year,constraints);
     
              constraints.anchor = GridBagConstraints.NORTHWEST;
              constraints.gridx = 2;
              constraints.gridy = 2;
              constraints.insets.left = 50;
              contentpane.add(new JLabel(" year"),constraints);
     
     
     
     
     
     
     
     
     
              constraints.anchor = GridBagConstraints.WEST;
              constraints.gridx = 0;
              constraints.gridy = 2;
              constraints.insets.left = 10;
              constraints.insets.top = 25;
              contentpane.add(new JLabel("Address"),constraints);
     
              constraints.anchor = GridBagConstraints.WEST;
              constraints.gridx = 1;
              constraints.gridy = 2;
              constraints.gridwidth = 4;
              contentpane.add(address,constraints);
     
     
              constraints.insets.top = 0;
              constraints.anchor = GridBagConstraints.NORTHWEST;
              constraints.gridx = 0;
              constraints.gridy = 3;
              constraints.insets.left=10;
              contentpane.add(new JLabel("Enrollment Number:"),constraints);
     
              constraints.anchor = GridBagConstraints.NORTHWEST;
              constraints.gridx = 1;
              constraints.gridy = 3;
              constraints.insets.left=23;
              contentpane.add(enrollmentnumber,constraints);
     
     
              constraints.anchor = GridBagConstraints.NORTHWEST;
              constraints.gridx = 2;
              constraints.gridy = 3;
              contentpane.add(new JLabel("Phone Number: "),constraints);
     
              constraints.anchor = GridBagConstraints.NORTH;
              constraints.gridx = 2;
              constraints.gridy = 3;
              constraints.insets.left=85;
              contentpane.add(phonenumber,constraints);
     
     
     
              constraints.anchor = GridBagConstraints.WEST;
              constraints.gridx = 0;
              constraints.gridy = 6;
              constraints.insets.left=220;
              contentpane.add(submit,constraints);
     
     
             submit.addActionListener(this);
     
     
           }
     
       public void actionPerformed(ActionEvent ae)
            {  if(ae.getSource()==submit)
                 {JOptionPane.showMessageDialog(null,"Done!!!");
     
     
                  try 
                 	{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   	  con = DriverManager.getConnection("jdbc:odbc:projectdsn");
                   	  s = con.createStatement();
                      s.executeUpdate("INSET INTO Student VALUES ('1', 'saurabh', '24')");
     
                      //ResultSet rset = s.getResultSet();
                      con.close(); 
                   }
                 catch(ClassNotFoundException exp)
                    {System.err.println(exp);
                    }
     
                catch(SQLException exp)
                   {System.err.println(exp);
                   }
     
     
               }// end of if statement
     
          }
        }

    *****************Error Message******************************

    Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: acc
    ess denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)
    at java.security.AccessControlContext.checkPermission (AccessControlConte
    xt.java:323)
    at java.security.AccessController.checkPermission(Acc essController.java:
    546)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:532)
    at java.lang.SecurityManager.checkPackageAccess(Secur ityManager.java:151
    2)
    at sun.applet.AppletSecurity.checkPackageAccess(Apple tSecurity.java:266)

    at sun.applet.AppletClassLoader.loadClass(AppletClass Loader.java:141)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at addstudent.actionPerformed(addstudent.java:198)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:19
    95)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.jav
    a:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel
    .java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242
    )
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonL
    istener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6267)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:603 2)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577
    )
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)

    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThre
    ad.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.
    java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThre
    ad.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)

    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)

    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Problem With Applet Connecting With Microsoft Access Database

    For future reference, please wrap your code with the code tags. To try and solve your problem, sign your applet. See What Applets Can and Cannot Do (The Java™ Tutorials > Deployment > Applets)

Similar Threads

  1. Replies: 1
    Last Post: June 14th, 2011, 12:08 PM
  2. Database access..
    By _lithium_ in forum JDBC & Databases
    Replies: 7
    Last Post: March 2nd, 2011, 10:32 PM
  3. Connecting to Access 2007 Database
    By aussiemcgr in forum JDBC & Databases
    Replies: 12
    Last Post: December 14th, 2010, 04:42 PM
  4. Looking at Exploring Database Connecting
    By aussiemcgr in forum JDBC & Databases
    Replies: 2
    Last Post: August 12th, 2010, 04:40 PM
  5. Connecting to a database
    By fwashington in forum JDBC & Databases
    Replies: 5
    Last Post: March 15th, 2010, 02:37 PM

Tags for this Thread