gpt4 book ai didi

Java Sql Server 2k5 连接错误

转载 作者:行者123 更新时间:2023-12-01 14:09:36 25 4
gpt4 key购买 nike

这是我的代码:

public static void addRecord(String name, int index) throws IllegalAccessException, InstantiationException, SQLException, ClassNotFoundException {
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

String dbURL = "jdbc:sqlserver://localhost\\sqlexpress";
String user = "sa";
String pass = "mypass";
Connection conn = DriverManager.getConnection(dbURL, user, pass);
PreparedStatement Prep = conn.prepareStatement("insert into tblAll(AdSoyad,SiraNo) values(?,?);");
Prep.setString(2, name);
Prep.setInt(3, index);
Prep.execute();
Prep.close();
Prep = null;
conn.close();
conn = null;
}

以下是我收到的错误:

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The index 3 is out of range.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setValue(SQLServerPreparedStatement.java:709)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setInt(SQLServerPreparedStatement.java:870)
at jmssql.JMsSQL.addRecord(JMsSQL.java:29)
at jmssql.JMsSQL.main(JMsSQL.java:19)

如果我添加 dbUrl“integratedSecurity=true;”部分;

错误在于;

com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path

我找不到任何修复它的想法,我该如何修复它?

最佳答案

这一行有错误

 PreparedStatement Prep = conn.prepareStatement("insert into tblAll(AdSoyad,SiraNo) values(?,?);");
Prep.setString(2, name);
Prep.setInt(3, index);

更改为

PreparedStatement Prep = conn.prepareStatement("insert into tblAll(AdSoyad,SiraNo) values(?,?);");
Prep.setString(1, name);
Prep.setInt(2, index);

关于Java Sql Server 2k5 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18629382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com