1

I've written a simple code which is used to insert and retrieve the employee details from a mysql database.I'm using apache tomcat8.0 server installed in eclipse oxygen version. The code is error free but when I try to run it i'm getting an error as applet is not initialized. I have looked at similar posts here but they aren't related to my issue.

import java.applet.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public  class WebApp extends Applet implements ActionListener{
Button b1,b2,b3;
Label l1,l2,l3,l4,l5,l6;
TextField t1,t2,t3,t4,t5,t6;
public void init()
{
    l1=new Label("First Name:");
    t1=new TextField(30);
    l2=new Label("Last Name:");
    t2=new TextField(30);
    l3=new Label("ID");
    t3=new TextField(30);
    l4=new Label("year");
    t4=new TextField(20);
    l5=new Label("designation");
    t5=new TextField(20);
    l6=new Label("salary");
    t6=new TextField(20);
    b1=new Button("push");
    b1.addActionListener(this);
    b2=new Button("get");
    b2.addActionListener(this);
    b3=new Button("go to home page");
    b3.addActionListener(this);
    add(l1);
    add(t1);
    add(l2);
    add(t2);
    add(l3);
    add(t3);
    add(l4);
    add(t4);
    add(l5);
    add(t5);
    add(l6);
    add(t6);
    add(b1);
    add(b2);
    add(b3);
}


public void actionPerformed(ActionEvent e)
{
    //  b1.getString();
    if(e.getSource()==b1)
try
{  
Class.forName("com.mysql.jdbc.Driver");  
Connection con=DriverManager.getConnection( 
"jdbc:mysql://localhost:8080/iyan","admin","admin");  
/*Statement stmt=con.createStatement();  
ResultSet rs=stmt.executeQuery("select * from emp");  
while(rs.next())  
(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
con.close();*/  
}
catch(Exception e)
{
    e.printStackTrace();
}

}
    public void paint(Graphics g ){
    ActionEvent e;
    if(e.getSource==b2){
    Connection con;
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("select * from emp");
    while(rs.next())
{
    String str=rs.getString("firstname");
    String displayOutput="firstname"+str;
    g.drawString(displayOutput);
    stmt.close();
}
stmt=con.createStatement();
ResultSet newTable=stmt.executeQuery("create table csed(sno int,name char(10)");
String msg="coloumn created"+newTable;
g.drawString(msg,10,20);
}
else
{
    return;
}
}
}
public static void main(String[] args)
{
public void run()
{
WebApp w=new WebApp();
w.start();
}
}
  • 2
    [Oracle reveals Java Applet API deprecation plan](https://www.theregister.co.uk/2016/08/24/oracle_reveals_java_applet_api_deprecation_plan/), [Why applets in JDK 9 are deprecated?](https://stackoverflow.com/questions/45535112/why-applets-in-jdk-9-are-deprecated), [The clock is ticking: The Java browser plugin will be deprecated soon](https://jaxenter.com/clock-ticking-java-browser-plugin-will-deprecated-soon-131546.html), [Oracle Reminds Java Developers That Soon They Won’t Have a Browser to Run Applets](https://www.infoq.com/news/2017/02/oracle-java-browser-applet) – MadProgrammer Jan 19 '18 at 05:59
  • 2
    [Oracle Announces End Of Java Applet Support](http://www.i-programmer.info/news/80-java/9391-oracle-annouces-the-end-of-java-applet-support.html), [Oracle's finally killing its terrible Java browser plugin](https://www.theverge.com/2016/1/28/10858250/oracle-java-plugin-deprecation-jdk-9) – MadProgrammer Jan 19 '18 at 05:59
  • 1
    Applets are a dead technology and you are better off finding a better solution to solve your problem. There are lots of reasons why a applet might fail to initialise and you will need to inspect the Java Console to find more information – MadProgrammer Jan 19 '18 at 06:01
  • 1
    Also, your code won't compile, so I'd investigate that first. Also, don't use custom paint this way (reading a `ResultSet`), as `paint` can be called for any number of reasons, many of which you simply don't have control over – MadProgrammer Jan 19 '18 at 06:02

0 Answers0