Insert in Table


Leave a reply                     

Insert in Table in Java

MySql Insert into Table

Java Insert in MySql table

How to Insert Data in MySql Table in Java

Following INSERT statement is used to insert data “www.” in database table tablename in column columnname2, the value for column columnname1 automatically inserted since it is auto increment column.
INSERT INTO tablename(columnname2) values (‘www.’)

package raghuwansh.java.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class InsertInTable {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection connection = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/databasename", "root", "");
			Statement statement = connection.createStatement();
			statement
					.executeUpdate("INSERT INTO tablename(columnname2) values ('www.')");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *


− 3 = four