I have got adding a member to the database working. I am trying to work out how to update a row in the table using the same system of passing in the values just not adding a new row, just altering the row using the passed in username.
Here is my method for inserting a new member:
public static void insertMember(String username,String firstName)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement st = connection.prepareStatement("INSERT INTO Members VALUES (?,?)");
st.setString(1, username);
st.setString(2, firstName);
st.executeUpdate();
}
catch (SQLException e)
{
System.out.println("SQL Exception: "+ e.toString());
}
catch (ClassNotFoundException cE)
{
System.out.println("Class Not Found Exception: "+ cE.toString());
}
}
INSERTstatement will insert rows in a table, whileUPDATEstatement will update a row (or a group of rows) in a table.