我的目标是使用 SQL 命令从数据库中检索数据,然后使用从单元格中检索的数据作为方法的参数,并将函数的结果保存在数据库中。
例如:
id column1 column2 result
1 5 9 --
2 22 40 --
我想要的是一个命令,用于使用 SQL 查询从 column1 和 column2 中检索数据,然后将它们用作 a 方法的参数(示例:minus(column2,column1)//它计算 2 的数据之间的差异列)然后将结果保存在名为结果的列中。然后对数据库的所有列执行此操作。
最佳答案
我会给你一个小例子,尽管你应该在 JDBC 和特别是在 ResultSet 上有很好的阅读。 :
//create an SQL statement first..
statement = conn.prepareStatement("SELECT * FROM my_table WHERE column_name=?");
//obtain the result set...
ResultSet resultSet = statement.executeQuery();
// here you obtain an array from the resultset, but you can fetch many other data types
String[] arrayResult = resultSet.getArray(String columnLabel);
// and then you can pass an element of that array (say the first element) as an argument to a method
myClass.myMethod(arrayResult[0]);
关于java - 从数据库中检索数据,将数据用作 java 方法的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27564527/