Friday, January 19, 2018

Java MySQL INSERT (using Statement)

See also: MySQL XAMPP Connection for Java jdbc Program

First suppose we have a table in out database named user. Or we can create a simple table like below:



Now we want to insert one record in this table. By following some steps we will do that.
  • Create a Java Connection to our MySQL database.
  • Create a SQL INSERT statement.
  • Then execute a Java Statement, using our SQL INSERT statement.
  • Close our Java MySQL database connection.
  • Finally catch any SQL exceptions using try-catch clause.


quey1 is passing direct values to the table. query2 is passing values through variables. Be careful about quote marks for executing queries.

See also:
Reference

No comments:

Post a Comment