我正在尝试设计一个将数据存储在Oracle数据库中的小程序。
没有编译错误,但是当我尝试通过单击ADD
按钮插入记录时,它会引发异常:
oracle.driver.OracleDriver
这是我的applet代码:
import java.applet.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
/*<applet code=registration width=400 height=400></applet>*/
public class registration extends Applet implements ActionListener
{
Label name;
TextField txt_name;
Button btn_add;
Connection con;
PreparedStatement pstmt;
public void init()
{
setLayout(null);
name=new Label("Name");
name.setBounds(10,20,50,20);
add(name);
txt_name=new TextField(20);
txt_name.setBounds(80,20,120,20);
add(txt_name);
btn_add=new Button("ADD");
btn_add.setBounds(10,50,50,20);
add(btn_add);
btn_add.addActionListener(this);
}//end of init
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn_add) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
pstmt=con.prepareStatement("insert into test values(?)");
pstmt.setString(1,txt_name.getText());
pstmt.executeUpdate();
System.out.println("saved");
} catch(Exception c) {
System.out.println(c.getMessage());
}
}
}
}
答案 0 :(得分:0)
检查以下内容: