我遇到问题,因为我无法插入到sql server数据库中:
驱动程序:[Microsoft] [用于JDBC的SQLServer 2000驱动程序] [SQLServer]
public int sendCabecera(String tpv, Date date, String time, int NumPers, int CodOfi) {
java.sql.DatabaseMetaData dm = null;
int result = 0;
try {
connection = this.getConnection();
if (connection != null) {
dm = connection.getMetaData();
Statement select = connection.createStatement();
String sql="INSERT INTO TCabecerasSolicitudes(CodigoTPV, FechaYHora, Hora, NumeroPersonas, CodigoOficina) VALUES ('001','17/08/2011 16:00','De 16 a 17',0, '001');";
select.execute(sql);
//{.... catch ... etc }
我已经尝试了所有执行更新并单独执行,我总是遇到同样的错误: “无法插入NULL”这是第一个作为主键的comlumn,通常是自动递增,所以我只是忽略它但是它不起作用???
提前多多感谢,
编辑:问题解决了我发现问题的关键不是自动增量
答案 0 :(得分:1)
您TCabecerasSolicitudes
表中的列似乎很可能被定义为NOT NULL
但未在您的插入语句中列出(即不是CodigoTPV, FechaYHora, Hora, NumeroPersonas, CodigoOficina
之一)。
因为您没有在查询中为该列提供值,而且它是NOT NULL
,所以该语句正在爆炸。