elet中没有初始化applet(氧气)

时间:2018-01-19 05:55:35

标签: java java-ee applet tomcat8 eclipse-oxygen

我编写了一个简单的代码,用于从mysql数据库中插入和检索员工详细信息。我使用的是eclipse氧气版本中安装的apache tomcat8.0服务器。代码没有错误,但是当我尝试运行它时,由于applet未初始化,我收到错误。我在这里查看了类似的帖子,但它们与我的问题无关。

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();
}
}

0 个答案:

没有答案