• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC ODBC Concetivity

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI all
I am running an applet in which i am connecting it with sql7.0. I made a permission from the jdbcodbc sriver. My applet runs very well but when i enter some data in the text box and i click on the button to let the data pass to the databasei get the following error:
java.security.AccessControlExveption: access denied(java.lang.RuntimePermission
accessClassPackage.sun.jdbc.odbc)
below is my code for the above:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Example extends JApplet
{
JPanel perPanel;
JLabel lblAppId;
JLabel lblAppName;
JLabel lblAppPosition;

JTextField txtAppId;
JTextField txtAppName;
JComboBox comAppPosition;
JButton butAccept;

GridBagLayout gl;
GridBagConstraints gbc;
public void init()
{
createAppletContent();
}
protected void createAppletContent()
{
FlowLayout flow;
flow=new FlowLayout();
Container content=getContentPane();
content.setLayout(new GridLayout());
JTabbedPane tabbedPane = new JTabbedPane();
content.add(tabbedPane,flow);
perPanel = new JPanel();
perDetail();
tabbedPane.addTab("Personal Details",null,perPanel,"Personal Detail");
}
public void perDetail()
{
gl = new GridBagLayout();
gbc = new GridBagConstraints();
perPanel.setLayout(gl);
lblAppId = new JLabel("Applicant Id");
lblAppName = new JLabel("Applicant Name");
lblAppPosition = new JLabel("Applicant Position");
butAccept = new JButton("Accept");
txtAppId = new JTextField(5);
txtAppName = new JTextField(20);
String positions[] = {"Manager","Sales Executive","Sales Manager"};
comAppPosition = new JComboBox(positions);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 5;
gl.setConstraints(lblAppId,gbc);
perPanel.add(lblAppId);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 5;
gl.setConstraints(txtAppId,gbc);
perPanel.add(txtAppId);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 8;
gl.setConstraints(lblAppName,gbc);
perPanel.add(lblAppName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 8;
gl.setConstraints(txtAppName,gbc);
perPanel.add(txtAppName);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 1;
gbc.gridy = 11;
gl.setConstraints(lblAppPosition,gbc);
perPanel.add(lblAppPosition);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 4;
gbc.gridy = 11;
gl.setConstraints(comAppPosition,gbc);
perPanel.add(comAppPosition);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 3;
gbc.gridy = 20;
gl.setConstraints(butAccept,gbc);
perPanel.add(butAccept);
validateAction validateButton = new validateAction();
butAccept.addActionListener(validateButton);
}
class validateAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
if(obj == butAccept)
{
String appId = txtAppId.getText();
if (appId.length() == 0)
{
getAppletContext().showStatus("Applicant Id cannot be blank");
return;
}

String appName = txtAppName.getText();
if (appName.length() == 0)
{
getAppletContext().showStatus("Applicant Name cannot be blank");
return;
}
String position = String.valueOf(comAppPosition.getSelectedItem());
getAppletContext().showStatus(" ");
}

Object source = e.getSource();
if (source == butAccept)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con = DriverManager.getConnection("jdbc dbc:Example","sa","");
PreparedStatement stat=con.prepareStatement("insert into Example(cAppId,vAppName,vAppPosition)values(?,?,?)");
stat.setString(1,txtAppId.getText());
stat.setString(2,txtAppName.getText());
stat.setString(3,(String)comAppPosition.getSelectedItem());
stat.executeUpdate();
}
catch (Exception exception)
{
System.out.println("Error encountered while entering data in the database:"+ exception);
}
}
}
}
}
please reply soon
Thank You
Jitin.Rathod
[This message has been edited by Jitin Rathod (edited May 09, 2001).]
[This message has been edited by Jitin Rathod (edited May 09, 2001).]
[This message has been edited by Jitin Rathod (edited May 09, 2001).]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IE is not going to let an applet access a database unless it is certified. Try running it using AppletViewer and I bet it will work fine. You need to rethink how you want your applet to access the database... buy a certificate, update the policy data on every users PC, or use a servlet as a database proxy.
 
Jitin Rathod
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thomas
Thanks alot for ypur reply. As you said that i do not run my applet in ie rather run it in appletviewer, but Thomas i am running my applet through appletviewer then i have got that error. Thomas one more thing is can you please just make it more clear about buying the certificate.
And i am sorry again
Thank You
Jitin.Rathod
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What database are you using? This seems to work fine for me in Appletviewer.
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are interested in creating signed applets, the book Java Cryptography has a chapter on creating signed applets.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The reason is you have to set permission in java.policy file.
It can be set by using policytool.Its a tool which comed along with JDK.
U have to grant permission for accessing the database.
Xavier
 
Jitin Rathod
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Xavier
Thanks a lot for your reply. I tried what yoyu had instructed me to do but i am confused which permission should i select from the Permission drop down, what should be the target name and what should be the Action.
Regards
Jitin.Rathod
 
Jitin Rathod
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Xavier
please try to finish off solving my problem.
Thanks
Jitin.Rathod
 
Jitin Rathod
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please can any help me solving my problem
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem with the getConnection method where you had not given the password. please check it with proper password.
 
Jitin Rathod
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Shivanath, for ur reply. I do not have a password for my connection so what should i do now.
 
Jitin Rathod
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please try solving out my problem
 
Jitin Rathod
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for the great guidance. The problem was from my side only. I did not make a .java.policy file. But even i could not help i had not been told about it in my classes
Thank You,
Regards
JITIN.RATHOD
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic