gpt4 book ai didi

Java 准备语句错误

转载 作者:行者123 更新时间:2023-12-01 15:28:33 24 4
gpt4 key购买 nike

我有以下代码。它基本上尝试处理从 jsf 表单提交的数据,然后将数据插入数据库中的表中。现在我们安装的数据库相当旧......它是sql server 2000,所以我使用jtds作为驱动程序。代码:

 public void dbConnect(String db_connect_string,
String db_userid,
String db_password)
{
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(db_connect_string,
db_userid, db_password);
System.out.println("connected");
dateSubmitted = "dasdasd";
/*HERE THE STATEMENTS TO INSERT*/
java.sql.PreparedStatement insertData = null;
String insertStatement = "INSERT INTO SLMDATA VALUES(?,?,?,?,?,?,?,?,?,?,"
+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
insertData = conn.prepareStatement(insertStatement);
insertData.setString(1, serviceLogger);
insertData.setString(2, dateSubmitted);
insertData.setString(3, serviceName);
insertData.setString(4, department);
insertData.setString(5, division);
insertData.setString(6, businessServiceDescription );
insertData.setString(7, technicalServiceDescription);
insertData.setString(8, serviceCustomer);
insertData.setString(9, serviceCriticality);
insertData.setString(10, serviceRequestSystem);
insertData.setString(11, serviceCategory);
insertData.setString(12, serviceHours );
insertData.setString(13, availabilityTarget);
insertData.setString(14, lowIncidentResponseScale );
insertData.setString(15, lowIncidentResponseHrsType );
insertData.setString(16, lowResponseTimeText);
insertData.setString(17, mediumIncidentResponseScale);
insertData.setString(18, mediumIncidentResponseHrsType);
insertData.setString(19, mediumResponseTimeText);
insertData.setString(20, highIncidentResponseScale);
insertData.setString(21, highIncidentResponseHrsType );
insertData.setString(22, highResponseTimeText );
insertData.setString(23, lowIncidentResolutionScale );
insertData.setString(24, lowIncidentResolutionHrsType );
insertData.setString(25, lowResolutionTimeText );
insertData.setString(26, mediumIncidentResolutionScale );
insertData.setString(27, mediumIncidentResolutionHrsType );
insertData.setString(28, mediumResolutionTimeText );
insertData.setString(29, highIncidentResolutionScale );
insertData.setString(30, highIncidentResolutionHrsType);
insertData.setString(31, highResolutionTimeText );
insertData.setString(32, blockTime );
insertData.setString(33, impactedServices);
insertData.setString(34, operationalDependencies );
insertData.setString(35, disasterAvailable );
insertData.setString(36, configurationItems );
insertData.executeUpdate();

conn.close();
FacesContext.getCurrentInstance().getExternalContext().dispatch("thankyou.xhtml");

} catch (Exception e) {
e.printStackTrace();
}
}


public void callConnection(){

dbConnect("jdbc:jtds:sqlserver://host;", "username",
"password");
}

glassfish 服务器控制台输出显示:

java.sql.SQLException: Invalid object name 'SLMDATA'.

SLMDATA 是表的名称,我确信它是正确的。当我通过断点功能单步执行代码时,我会到达executeQuery,然后事情就会失去控制。我已经查看了所有变量的内容,并且所有变量都是有效的。知道发生了什么事吗?被困在这个问题上有一段时间了

最佳答案

您应该尝试将架构名称放在表 schemaName.table 之前,或者在数据库中为该架构创建一个同义词。

关于Java 准备语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9869900/

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