hi all,
i m trying to insert a textfield's value in a table through applet.The table name is samp and it has only one column named 'name'.I did following control panel->admin tools->data source->and then i have added a 'bike2' as new data source.
I have 4 files created.
1.Entry.java
2.Bikinfa.java
3.Connect.java
4.Insert.java

the following is the code for each file
Entry.java

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.JComboBox;
import javax.swing.border.*;
import java.sql.*;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.Calendar;
import javax.swing.JOptionPane;

import java.io.*;

public class Entry{
	
	public static void main(String args[])
		{
			new Bikfina();
	}
}

following code is this is for Connect

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.DriverManager;
import java.sql.*;
public class Connect
{
		public Connection conn;
	
		public PreparedStatement stmt,stu;
		
	
	PreparedStatement ps;

	ResultSet rs;
	static String url = "jdbc:odbc:bike2";
	static Connection con;
	Statement stm;
	
public Connect()
{

	try {

			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

		} catch (java.lang.ClassNotFoundException e) {
			System.out.println(e);
		}

	try {
			con = DriverManager.getConnection(url,"scott", "tiger");
		} catch (Exception e1) {
			System.out.println(e1);
		}


}
}

the following code is for the Insert

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.JComboBox;
import javax.swing.border.*;
import java.sql.*;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.Calendar;
import javax.swing.JOptionPane;

import java.io.*;
public class Insert extends Frame


{
	
	Button ok=new Button("ok");
	Button cancel=new Button("cancel");
	TextField tf=new TextField();
	
	public Insert()
	{	
	System.out.println("m at insert");
	}
	
	public void inserrec()
		{
			
System.out.println("m at insert rec");


Bikfina bk1=new Bikfina();




System.out.println("at name: "+bk1.ok.getName());


    	Connect c=new Connect();
 				try
   			{
   				
   	  				
   		ok.setSize(80,20);
		ok.setLocation(50,260);
		cancel.setSize(120,20);
		cancel.setLocation(300,260);
	
		tf.setSize(190,20);
		tf.setLocation(400,260);
	
	
		
		add(ok);
		add(cancel);
		add(tf);
		
   				System.out.println ("qweq");
   		  			
   			c.stmt=c.conn.prepareStatement("insert into samp(name) values(?)",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
				
				c.stmt.setString(1,tf.getText());
		
			}
			catch(Exception e)
			{
			System.out.println (e);	
			}	
	}
	
}

following code is for Bikinfa

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Bikfina extends Applet 
{
		
	Button ok=new Button("ok");
	Button cancel=new Button("cancel");
	TextField tf=new TextField();

	public void init()
	{
		ok.setSize(80,20);
		ok.setLocation(50,260);
		ok.setName("ok's name is ook ;-) ");
		
		cancel.setSize(120,20);
		cancel.setLocation(300,260);
	
		tf.setSize(190,20);
		tf.setLocation(400,260);
	
		add(ok);
		add(cancel);
		add(tf);

		
		ButtonHandler bh=new ButtonHandler();
		ok.addActionListener(bh);
		cancel.addActionListener(bh);
		
		}	
			
		
		
public class ButtonHandler implements ActionListener	{	
			
public  void actionPerformed(ActionEvent ae)
				{
	
	Insert i=new Insert();		
		System.out.println("sddd6");
	
			
	try{
						System.out.println("sddd7");
			if(((Button)ae.getSource())==ok)
					{
				System.out.println(ae.getSource()+"m at ok now");		

					i.inserrec();

					}
					
					
			if(((Button)ae.getSource())==cancel)

					{
						System.out.println("cancel");
		
					}
					
		}
		catch(Exception e)
			{
				System.out.println(e);
			}
}


}

	public void paint(Graphics g)
	{
		g.drawString("Welcome to Java!!", 80, 80 );
	}

}

i think the error comes at the connect block.it says about access denied.some friennds told me that applet has some resttrictions t oinvoke local files..some other friend said about type 4 drivers to be used.i m not getting what is the fault..plz guys help this new bee ...i get the following error


m at insert
sddd6
sddd7
java.awt.Button[ok's name is ook ;-) ,194,5,27x23,label=ok]m at ok now
m at insert rec
at name: button0
java.security.AccessControlException: access denied (java.lang.RuntimePermission
accessClassInPackage.sun.jdbc.odbc)

guyss plz help me..its urgent :(

Recommended Answers

All 3 Replies

put that (java.security......) to google (I'd preferred links to official Oracle Pages)

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.