aspose file tools*
The moose likes JDBC and the fly likes JDBC ODBC Concetivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC ODBC Concetivity" Watch "JDBC ODBC Concetivity" New topic
Author

JDBC ODBC Concetivity

Jitin Rathod
Greenhorn

Joined: Apr 25, 2001
Posts: 19
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).]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jitin Rathod
Greenhorn

Joined: Apr 25, 2001
Posts: 19
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
Ranch Hand

Joined: May 05, 2000
Posts: 13974
What database are you using? This seems to work fine for me in Appletviewer.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
If you are interested in creating signed applets, the book Java Cryptography has a chapter on creating signed applets.
Xavier VS
Greenhorn

Joined: May 11, 2001
Posts: 7
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

Joined: Apr 25, 2001
Posts: 19
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

Joined: Apr 25, 2001
Posts: 19
Hi Xavier
please try to finish off solving my problem.
Thanks
Jitin.Rathod
Jitin Rathod
Greenhorn

Joined: Apr 25, 2001
Posts: 19
Please can any help me solving my problem
shivanath yerra
Greenhorn

Joined: Jan 17, 2002
Posts: 14
I think the problem with the getConnection method where you had not given the password. please check it with proper password.
Jitin Rathod
Greenhorn

Joined: Apr 25, 2001
Posts: 19
Thanks Shivanath, for ur reply. I do not have a password for my connection so what should i do now.
Jitin Rathod
Greenhorn

Joined: Apr 25, 2001
Posts: 19
please try solving out my problem
Jitin Rathod
Greenhorn

Joined: Apr 25, 2001
Posts: 19
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
 
wood burning stoves
 
subject: JDBC ODBC Concetivity