Reputation: 67
I have looked at other stackoverflow threads to get an answer for this problem. Mostly what I see is that it is caused by typos, although I cannot see any in this method. This method is called from another method in the same class and when run returns the error :
java.sql.SQLException: No value specified for parameter 1
The code for my class is here:
public void WriteTag(String tagPrefix, String tagName, String tagContent)
{
try {
String query = String.format("INSERT INTO %s(%s,%s) VALUES(?,?)",
tagPrefix, TAGNAME_COLUMN, TAGCONTENT_COLUMN);
PreparedStatement sqlStatement = connection.prepareStatement(query);
sqlStatement.setString(1, tagName);
sqlStatement.setString(2, tagContent);
//sqlStatement.executeUpdate();
} catch(Exception e) {HandleException(e);}
}
I'm not really sure what is wrong here. The constants are properly defined elsewhere in the code. Does anyone see what I am doing wrong?
Upvotes: 4
Views: 13406
Reputation: 5471
Try this
String query = "Insert into foo (foo1,foo2) Values (?,?)";
PreparedStatement pst = connection.prepareStatement(query);
pst.setString(1, whatever);
pst.setString(2, whatever);
pst.executeUpdate(); // this is actually important in order to get data inserted into database.
So technically hardcode the tablenames that are in the databse. and it should work.
Upvotes: 1