在JFRAME上添加几个JTextField。想从中得到数据并插入到ORACLE数据库但总是抛出java.sql.SQLException: ORA-01400: 无法将 NULL 插入 ("SYSTEM"."PROJECT"."PID")异常。所有的数据在数据库中定义为char(10) 代码: JTextField pidT = new JTextField(); JTextField pnameT = new JTextField(); JTextField psourceT = new JTextField(); JTextField pmoneyT = new JTextField(); JTextField proleT = new JTextField(); JTextField ptimeT = new JTextField(); pid = pidT.getText();
pname = pnameT.getText();
psource = psourceT.getText();
pmoney = pmoneyT.getText();
prole = proleT.getText();
ptime = ptimeT.getText();
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String s = "insert into project values('" + pid + "','"
+ pname + "','" + psource + "','" + pmoney
+ "','" + prole + "','" + ptime + "')"; st.executeUpdate(s);
JOptionPane.showMessageDialog(null, "添加成功");
} catch (Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "添加失败");
}
}
});
pname = pnameT.getText();
psource = psourceT.getText();
pmoney = pmoneyT.getText();
prole = proleT.getText();
ptime = ptimeT.getText();
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String s = "insert into project values('" + pid + "','"
+ pname + "','" + psource + "','" + pmoney
+ "','" + prole + "','" + ptime + "')"; st.executeUpdate(s);
JOptionPane.showMessageDialog(null, "添加成功");
} catch (Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "添加失败");
}
}
});
{
public void actionPerformed(ActionEvent e)
{ pid = pidT.getText();
pname = pnameT.getText();
psource = psourceT.getText();
pmoney = pmoneyT.getText();
prole = proleT.getText();
ptime = ptimeT.getText();
try
{String s = "insert into project values('" + pid + "','"
+ pname + "','" + psource + "','" + pmoney
+ "','" + prole + "','" + ptime + "')";st.executeUpdate(s);
JOptionPane.showMessageDialog(null, "添加成功");
} catch (Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "添加失败");
}
}
});
String s = "insert into project values('" + pid + "','"
+ pname + "','" + psource + "','" + pmoney
+ "','" + prole + "','" + ptime + "')";pid,pname...都是外部类的,内容类没看到,就是看到了也是final,所以错了
你应该动态的获取这些值,所以你需要把那些值的获得放到事件监听器中
方法:System.out.println(。。)然后就是重点看下你的sql语句是否有错误。一般在做处理数据库的编程中sql语法的正确很重要