I am taking a web design and development class and we have been thrown into MySQL along with java without much knowledge beforehand. Was wondering if anyone could help me with understanding how to query the database and update entries, as I am confused on how to accomplish this.
I am able to insert new entries and display table info, but when it comes to adding to existing info nothing seems to work. I can get the statement to work if I supply the data in the SQL statement i.e UPDATE tableName SET columnName1 = value1, WHERE criteria. But when I attempt to use user input and send variables along nothing seems to work.

Any help would be appreciated.

Thanks

Recommended Answers

All 4 Replies

Can you post a SSCCE to demonstrate your problem?

//modify existing author info
	public void ModifyAuthorInfo() throws SQLException {
		
		String authorsFirstName, authorsLastName, newFirstName, newLastName;
		
		modifyAuthor = connection.prepareStatement("UPDATE authors SET firstName = ?, lastName = ? WHERE firstName = ? AND lastNAME = ?");
		
		authorsFirstName = GetAuthorFirstName();
		authorsLastName = GetAuthorLastName();
		newFirstName = GetAuthorFirstName();
		newLastName = GetAuthorLastName();
		
		//modifyAuthor.setString(1, authorsFirstName);
		//resultSet = modifyAuthor.executeQuery();
		
		modifyAuthor.setString(1, authorsFirstName);
		modifyAuthor.setString(2, authorsLastName);
		modifyAuthor.setString(3, newFirstName);
		modifyAuthor.setString(4, newLastName);
		
		modifyAuthor.executeUpdate();
	}
//modify existing author info
	public void ModifyAuthorInfo() throws SQLException {
		
		String authorsFirstName, authorsLastName, newFirstName, newLastName;
		
		modifyAuthor = connection.prepareStatement("UPDATE authors SET firstName = ?, lastName = ? WHERE firstName = ? AND lastNAME = ?");
		
		authorsFirstName = GetAuthorFirstName();
		authorsLastName = GetAuthorLastName();
		newFirstName = GetAuthorFirstName();
		newLastName = GetAuthorLastName();
		
		//modifyAuthor.setString(1, authorsFirstName);
		//resultSet = modifyAuthor.executeQuery();
		
		modifyAuthor.setString(1, authorsFirstName);
		modifyAuthor.setString(2, authorsLastName);
		modifyAuthor.setString(3, newFirstName);
		modifyAuthor.setString(4, newLastName);
		
		modifyAuthor.executeUpdate();
	}

Disregard this post- I realized just as I submitted it that I had the new names in the wrong spots so I was never finding the correct entry in the table. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.