我的access数据库的字段为编号(关键字),date,product.
我编写了一个添加一条记录的程序,如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import   javax.swing.table.*;   
import   java.util.*;   
public class Addrec1 extends JFrame implements ActionListener
{
private Connection co;
 private   JPanel   pane1   =   null;
 private   JPanel   pane2   =   null;
 private   JPanel   pane3   =   null;
 private   JButton   insert =   new JButton("执行");
 private JTextField t1=new JTextField("",20);
 private JTextField t2=new JTextField("",20);

 private Container c;
public  Addrec1(Connection con2)
{
JFrame frame   =   new   JFrame("按日期");
pane1   =   new   JPanel();  
pane2   =   new   JPanel();  
pane3   =   new   JPanel();  
co=con2;
c=getContentPane();
pane1.add(new JLabel("增加新记录"));
  pane2.add(new JLabel("请输入日期"));
pane2.add(t1);
pane2.add(new JLabel("请输入产品"));
pane2.add(t2);

pane3.add(insert);
c.add(pane1,BorderLayout.NORTH);
c.add(pane2,BorderLayout.CENTER);
c.add(pane3,BorderLayout.SOUTH); 
insert.addActionListener(this);
setSize(800,500);
setVisible(true); 
}
public void actionPerformed(ActionEvent e)
{ try
{
if ((!(t1.getText().equals(""))&(!t2.getText().equals(""))))
{
PreparedStatement pstmt=co.prepareStatement("insert table1 ( date,product) values(?,?)");
String date1=t1.getText();
String product=t2.getText();

pstmt.setString(1,date1);
pstmt.setString(2,product);

pstmt.executeUpdate();
JOptionPane.showMessageDialog(null,"添加成功");



  
pstmt.close();

}
else
JOptionPane.showMessageDialog(null,"您没有输入完全");

  }
  catch(SQLException e2)
  {
   JOptionPane.showMessageDialog(null,"数据库插入失败"); 
  }
  
}
}
编译已经成功,但是调试结果一直是数据库插入失败.请各位大虾指点一下.