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.:)..

The error message should give you the exact line number where it happened. Care to share it with us?

i get that error in appletviewer.exe in console the black window..there is no line number or anyother number ..

Sorry - I missed the mistakes on lines 94 and 111. Replace both with
e.printStackTrace();
so you get the full details of the error.

ps and 62

java.security.AccessControlException: access denied (java.lang.RuntimePermission
accessClassInPackage.sun.jdbc.odbc)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:151
2)
at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:266)

at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:124)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at Appletsamp$Connect.<init>(Appletsamp.java:66)
at Appletsamp$ButtonHandler.actionPerformed(Appletsamp.java:86)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
java.lang.NullPointerException
at Appletsamp$ButtonHandler.actionPerformed(Appletsamp.java:98)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.