Mysql& MSAccess:插入到具有递增字段的表中 [英] Mysql&MSAccess: insert into table which have an incremented field

查看:232
本文介绍了Mysql& MSAccess:插入到具有递增字段的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,如果有重复,但我尝试了所有的方式仍然不能插入。

I am sorry if there is a duplicate but I tried all ways still I can't do the insertion.

我有一个表只有两个字段,Name)
当我运行这个SQL代码,它必须插入一个新的记录,并增加 ID 字段自动
,因为它是自动增量,但不幸的是不工作。
查看跟踪和错误:

I have a table with only two fields ( ID , Name ) When I run this SQL code it must be insert a new record and increment the ID field automatically because it's auto increment but unfortunately don't work . See the trail and errors :

MYSQL


  1. PreparedStatement pr = con.prepareStatement(insert into names(name)values(?));
    pr.setString(2,Azad);

java.sql.SQLException:Parameter索引超出范围(2>参数数量,为1)。

名称(id,名称)值(?,?)

java.sql.SQLException:参数1

>

MS Access :


  1. 插入名称(名称)值(?)

  1. insert into names(name) values(?)

java.lang.ArrayIndexOutOfBoundsException:1

java.lang.ArrayIndexOutOfBoundsException: 1


  1. 插入到名称(id,name)值(?,?)

  1. insert into names(id,name) values (?,?)

java.sql.SQLException:[Microsoft] [ODBC Microsoft Access Driver] COUNT字段不正确

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect

这些错误的原因是什么?

What's the reason of those errors ? and how to solve it ?

推荐答案

感谢您的建议和解答。 p> change pr.setString(2,Azad); to pr.setString(1,Azad);

change pr.setString(2,"Azad"); to pr.setString(1,"Azad");

第一个参数与位置有关?在预准备的语句中,不是表中的列索引。

The first parameter is related to the position of the ? in the prepared statement, not the column index in the table.

java.sql.SQLException:没有为参数1指定值。这是因为你有为查询指定两个参数。但是只为第二个参数指定了一个值。如果ID是自动递增的列,那么您不需要传入值。如果它不是那么

java.sql.SQLException: No value specified for parameter 1. This is down to the fact that you have specified two parameters for the query. But have only specified one value, for the second parameter. If "ID" is an auto incremented column then you don't need to pass in a value. If its not then

pr.setString(1,IDVALUE);

pr.setString(1,IDVALUE);

pr.setString azad);

pr.setString(2,"Azad");

这篇关于Mysql& MSAccess:插入到具有递增字段的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆