import java.applet.*;
import java.awl.*;
import java.sql.*;
//other packages
public class jdb extends Applet
{
Connection con;
Statement stmt;
String name="drvijay";
String phoneno="9842088860";
public void init(){}
pubilc void stop(){}
public void destroy(){}
public void start()
{
call();
}
public void call()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("Jdbc:Odbc:emp","sa","");
stmt=conn.createStatement();
stmt.executeUpdate("insert into empdetails(name,phoneno) values ('"+name + "',''"+ phoneno +"' )" );
}catch(SQLException e)
{
System.out.println("error"+e);
System.exit(0);
}
}
};
//<applet code="jdb" height="200" width="200"> </applet>
/*
u this jdbc statement in any of the method..
*/
@ drvijayy2k2
I dont know how to connect to a database from an applet yet but I know there's no point making an applet which requires a odbc connection.
If an odbc connection is required, then its better to make it an application.
The purpose of making an applet with database connectivity is that it can de deployed to the net and the end user doesnt have to worry about creating a Data Source Name.
I am modify your program.
Like below:
import java.applet.*;
import java.awt.*;
import java.sql.*;
//other packages
public class jdb extends Applet
{
Connection con;
Statement stmt;
public void start()
{
call();
}
public void call()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:emp","system","manager");
stmt=con.createStatement();
stmt.executeUpdate("insert into stu1 values ('OK')");
}
catch(SQLException e)
{
System.out.println("error"+e);
}
}
}
/*
<html>
<body>
<applet code="jdb" height="200" width="200"> </applet>
</body>
</html>
*/
I am complie the program it say like below:
jdb.java.19:unreported exception java.lang.class not foundException:must be caugth or declared to be thrown
Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
> con=DriverManager.getConnection("Jdbc:Odbc:emp","system
> ","manager");
This line should be
con=DriverManager.getConnection("jdbc:odbc:emp","system","manager");
notice the caps.(java is Case sensitive)
The Class.forName() throws ClassNotFoundException
Also note that you have mentioned the SQLException only. You need to mention one more catch statement
catch(Exception e)
{
e.printStackTrace();
}
As I said before using a jdbc-odbc is not recommented if you plan to deploy this on the web.
Regards
Message was edited by:
ArcherKing
Oh I've forgot to mention that you have to set permissions.
I'm not at my home computer right now, so I cant give you exact procedure.
I can guide you a bit though.
run the policytool from the command prompt and set the permissions.
Can someone else help him out?
follow this link, hope it helps
http://forum.java.sun.com/thread.jspa?threadID=172396&tstart=0
Message was edited by:
ArcherKing