Inserting a Row into a Database Table - Java JDBC

Java examples for JDBC:Table

Description

Inserting a Row into a Database Table

Demo Code

import java.awt.Graphics;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
  public void m() {
    try {/*  w ww  .  ja  v a2 s.co  m*/
      Connection connection = null;
      Statement stmt = connection.createStatement();

      // Prepare a statement to insert a record
      String sql = "INSERT INTO my_table (col_string) VALUES('a string')";

      // Execute the insert statement
      stmt.executeUpdate(sql);
    } catch (SQLException e) {
    }
  }
}

Related Tutorials