Java jdbc中的递增值
我有一个名为DatabaseInterface的类,其中我在那里创建了表,并使用get Customer作为方法,如下所示:Java jdbc中的递增值,java,jdbc,sql-update,Java,Jdbc,Sql Update,我有一个名为DatabaseInterface的类,其中我在那里创建了表,并使用get Customer作为方法,如下所示: public static Customer getCustomer(long id) { System.out.println("Get customer " + id); Customer customer = new Customer(); try { statement = conn
public static Customer getCustomer(long id) {
System.out.println("Get customer " + id);
Customer customer = new Customer();
try {
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT * FROM customer where id = " + id);
if (resultSet.next())
{
long cId = resultSet.getLong("id");
String name = resultSet.getString("name");
long tagNo = resultSet.getLong("tagNo");
String email = resultSet.getString("EMAIL");
String telephoneNo = resultSet.getString("telephoneNo");
int noOfTimesRecycled = resultSet.getInt("No of Times Recycled");
customer = buildCustomer(cId, name, tagNo, telephoneNo, email, noOfTimesRecycled);
System.out.println(customer);
}
} catch (SQLException ex) {
System.out.println("Error in getting customer");
ex.printStackTrace();
}
return customer;
}
我有一个文本文件,它读取标记号的值,每次有一个新的标记条目,它就会增加标记号的值。
我在一个名为UpdateTag的新类中这样做。因此,我首先从DatabaseInterface类调用了getCustomer方法,然后将继续更新,但会出现错误
package com.qmul.rfid.service;
import java.util.List;
import com.qmul.rfid.dataaccess.DatabaseInterface;
//import com.qmul.rfid.dom.Customer;
import com.qmul.rfid.reader.ImportTagJob;
public class UpdateTag {
List<String> fileList = ImportTagJob.fetchData();
{
try{
for (String tag : fileList)
{
DatabaseInterface.getCustomer(long id); //Getting error on long id -Syntax error on token "long", delete this token
System.out.println(tag);
}
}
catch (IllegalArgumentException ex)
{
ex.printStackTrace();
}
}
}
知道为什么吗?但是出错了。。。想告诉我们更多信息吗?在DatabaseInterface.getCustomerlong id上获取错误-令牌long上的语法错误,删除此令牌long,删除此令牌。还有问题吗删除long并不能解决错误。它说id不能解析为变量,因为我没有在类中的任何地方声明它。我需要从customer表中检索值,以便能够增加其中一列中的值。所以我认为这是唯一的办法。@Sne这个错误是显而易见的,但是,对我来说,还不清楚你想要达到什么目的。建议您多花些时间,描述问题,并编辑您的原始帖子。