使用的是JBUILDER 9和SQLSERVER 2000,O/S为WIN2000 PRO现在有一个表publishers(pub_id varchar(4), pub_name(40), city varchar(20), state varchar(2), country varchar(30), URL varchar(80));
其中pub_id为主键PreparedStatement updatePublisher = connection.preparedStatement("UPDATE publishers SET
pub_name = ?, city = ?, state = ?, country = ?, URL = ?
WHERE pub_id = ?");updatePublisher.setString(1, aPublisher.getPuplisherName());
updatePublisher.setString(2, aPublisher.getCity());
updatePublisher.setString(3, aPublisher.getState());
updatePublisher.setString(4, aPublisher.getCountry());
updatePublisher.setString(5, aPublisher.getURL());
//下面这句抛出了SQLException异常
updatePublisher.setString(6, aPublisher.getPublisherID());测试前面5个语句均正常,getPublisherID() 返回String类型结果,
且经过测试getPublisherID()返回了一个非空的结果为什么会抛出SQLException,如何解决?谢谢
其中pub_id为主键PreparedStatement updatePublisher = connection.preparedStatement("UPDATE publishers SET
pub_name = ?, city = ?, state = ?, country = ?, URL = ?
WHERE pub_id = ?");updatePublisher.setString(1, aPublisher.getPuplisherName());
updatePublisher.setString(2, aPublisher.getCity());
updatePublisher.setString(3, aPublisher.getState());
updatePublisher.setString(4, aPublisher.getCountry());
updatePublisher.setString(5, aPublisher.getURL());
//下面这句抛出了SQLException异常
updatePublisher.setString(6, aPublisher.getPublisherID());测试前面5个语句均正常,getPublisherID() 返回String类型结果,
且经过测试getPublisherID()返回了一个非空的结果为什么会抛出SQLException,如何解决?谢谢
我在紧接updatePublisher.setString(6, aPublisher.getPublisherID());
和catch(SQLException e){}中设了两个输出
结果是紧接updatePublisher.setString(6, aPublisher.getPublisherID());没有输出
而catch中的输出却出现了
SQLException封装所有的数据库异常,只有从具体stack trace信息才能看出具体的错误,这样大家才能帮你。
楼主的是字符类型,应该不存在这个问题。有两年没用sqlserver了,不知道记忆是否正确。
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.validateParameterIndex(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.setObjectInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.setString(Unknown Source)
at bookmanagement.SQLPublisherDataAccess.updatePublisher(SQLPublisherDataAccess.java:141)
我看过原表中的pub_id都是不一样的
还有我这些标的数据都是从SQL SERVER 2000的pubs数据库中导过来的
--create table myNewTable(
--MemID int IDENTITY,
--MemName varchar(10)
--)
--select * from myNewTable
--insert into myNewTable values('Tiger')
--update myNewTable set MemName='Laohu' where MemID=1
更新记录的时候是可以读取IDENTITY字段的值的(update myNewTable set MemName='Laohu' where MemID=1语句工作正常),只是在IDENTITY_INSERT 不为 ON 时我们不能人为的显式给出IDENTITY字段的值!