Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Error

 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the written the following code:
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ProjTest extends JApplet implements ActionListener
{
JButton btOK;
Connection con;
Statement stat;
String url = "jdbc dbc rojTest";
String data = "Insert into Emp_Details " +
"Values('Patrick', 'Mugabe', 'E231', 'Programmer')";
public void init()
{
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
btOK = new JButton("Click");
cp.add(btOK);
btOK.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception ex)
{
getAppletContext().showStatus("Error on connection" +
ex.getMessage());
}
try
{
Connection con = DriverManager.getConnection(url, "", "");
stat = con.createStatement();
stat.executeUpdate(data);
}
catch(SQLException conex)
{
showStatus("Error reported " + conex.getMessage());
}
catch(Exception exc)
{
showStatus("check for data errors"); }
}
}
When I click the button (btOK) to insert data into my database, I am getting the following error:
Error reported No suitable driver.
Please help me on how I can overcome this error.
 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured that it was a problem to do with permissions so I resolved it using policyTool.
HOWEVER, I STILL HAVE ANOTHER PROBLEM. I am still getting an error if I use Internet Explorer but I have no problems when I use Appletviewer.
How can I solve this problem.
 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Are you trying to use an applet download from a web server and connect to a MySQL on localhost or other than the web server?
In that case, you need more security setting other than policy tool.
Have you configure the cert?
You can refer to this article
http://developer.java.sun.com/developer/technicalArticles/Security/Signed/index.html
Not exactly the same, but you need the same type of configuration for access in Applet.
Hope it helps.
Cheers.

Han Ming
 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the advise. It's different from what i wanted but close and very helpful. I think it will help me in getting over this problem.
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic