Reputation: 1422
I get a Java MySQL exception
@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;
}
I get the following error when I debug the following code :
java.sql.SQLException: No value specified for parameter 1
Someone do suggest a way to solve..Why I get such an exception?
Upvotes: 1
Views: 1117
Reputation: 10295
You're passing null
to executeQuery instead of list of arguments here:
Application.getDBHandler().executeQuery(SQLQueries.GET_PROPERTY, null);
So, the no value in the place of ?
in the query "Select * from app_config where Property = ?"
, hence the exception.
Hope this helps.
Upvotes: 3