在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, "添加失败");
}
}
});
解决方案 »
- 高手指点!利用java中的正则表达式解析html网页的问题?
- 请教一下高手, 怎样implement method stack by methods from queues, 急
- 关于记事本!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
- java中static方法问题
- 在AWT中是否可以向container Panel 中添加另一个container Panel?
- getImage(new URL("........"));的问题!!!!!
- 能帮忙看看么?
- 关于工厂模式的问题!
- 关于用java代码生成一个类(大家请进,建议者有分)
- 请问那位知道jdk中是否包含md5函数,望不吝赐教
- myeclipse中看类原始代码的问题
- 串口接收数据
b.addActionListener(new ActionListener()
{
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, "添加失败");
}
}
});
我在PIDT上输入了值,为什么getText()但不到呢?
pname = pnameT.getText();
psource = psourceT.getText();
pmoney = pmoneyT.getText();
prole = proleT.getText();
ptime = ptimeT.getText();
只要你在文本框中输入了信息,就能在b的事件中得到数据信息。你看一下是不是你别的代码出问题了。
getText()不能写在那里的,程序已经来就吧那些属性赋值为null了
在你的监听到动作后取值,可以先判断下是否为空