我得到一个 Java MySQL 异常
@Override
public ResultSet executeQuery (String query, ArrayList<Argument> arguments) throws SQLException
{
final PreparedStatement pstmt = getPstmt(query, arguments);
final ResultSet retrievedData = pstmt.executeQuery();
return retrievedData;
}
//getpstmt()
private PreparedStatement getPstmt (String query, ArrayList<Argument> arguments) throws SQLException
{
PreparedStatement pstmt = null;
try {
pstmt = connection.prepareStatement(query);
if (arguments != null) {
int argPosition = 1;
for (final Argument arg : arguments) {
if (arg.getType() == ARGUMENT_TYPE.INTEGER) {
pstmt.setInt(argPosition++, arg.getInt());
}
else {
pstmt.setString(argPosition++, arg.getString());
}
}
}
}
catch (final Exception ex) {
NmsLogger.writeDebugLog(ex);
return null;
}
return pstmt;
}
// One instance of calling executeQuery
public String getProperty(String propertyName)
{
try
{
ArrayList<Argument> arguments = new ArrayList<Argument>();
arguments.add(new Argument(propertyName));
final java.sql.ResultSet resultset = Application.getDBHandler().executeQuery(SQLQueries.GET_PROPERTY, null);
Application.getDBHandler().executeQuery(SQLQueries.GET_PROPERTY, arguments);
if(resultset.next())
{
resultset.getString(1);
}
return resultset.toString();
}
catch (SQLException e)
{
NmsLogger.writeDebugLog(e);
e.printStackTrace();
}
return null;
}
调试以下代码时出现以下错误:
java.sql.SQLException:没有为参数 1 指定值
有人确实建议了一种解决方法..为什么我会遇到这样的异常?