hi all! i have a saimple applet which tries to insert a text from textfield init oa table named samp.here is my code
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.awt.*;
import java.applet.*;
import java.sql.*;
import java.io.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Appletsamp extends Applet //implements ActionListener
{Button ok=new Button("ok");
Button can=new Button("cancel");
TextField tf=new TextField();
public void init()
{
ok.setSize(50,50);
ok.setLocation(200,200);
add(ok);
can.setSize(50,50);
can.setLocation(200,200);
add(can);
tf.setSize(900,600);
tf.setLocation(390,200);
add(tf);
ButtonHandler bh=new ButtonHandler();
ok.addActionListener(bh);
can.addActionListener(bh);
tf.addActionListener(bh);
}
public class Connect
{
public Connection conn;
public ResultSet rs;
public PreparedStatement stmt,stu;
public Connect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:bike","scott","tiger");
}
catch(Exception e)
{
System.out.println (e);
}
}
}
class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent ae)
{
Connect c=new Connect();
try{
if(((Button)ae.getSource())==ok)
{
try
{
c.stmt=c.conn.prepareStatement("insert into samp(name) values(?)");
c.stmt.setString(1,tf.getText());
c.stmt.executeQuery();
System.out.println (ae.getSource()+"ok");
}
catch(Exception e)
{
System.out.println(e +"ssss");
}
}
if( ((Button)ae.getSource())==can)
{
System.out.println (ae.getSource());
}
}
catch(Exception e)
{
System.out.println(e+"out");
}
}
}
public void paint(Graphics g)
{
g.drawString("Welcome to Java!!", 50, 60 );
}
}
following is the error which i m getting ...
java.security.AccessControlException: access denied (java.lang.RuntimePermission
accessClassInPackage.sun.jdbc.odbc)
java.lang.NullPointerExceptionssss
plz help this new bee guyss.:)..