title: Java Netbeans MySql database Connection
body: <p>I want to insert row into MySql database with a normal Program for Mysql connection in Java Netbeans,but when i run this code my database remains unaffected.I had setup connection with Netbeans and Mysql and it is working fine.</p>
  
  <p>Code:</p>
  
  <pre><code>    import java.sql.*;
  
      public class MySqlConnection {
  
  
         static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
         static final String DB_URL = "jdbc:mysql://localhost:3306/migration";
         static final String USER = "root";
         static final String PASS = "ngts12345";
  
         public static void main(String[] args) {
  
              Connection conn = null;
  
              try{
               Class.forName("com.mysql.jdbc.Driver");
               System.out.println("Connecting to a selected database...");
               conn = DriverManager.getConnection(DB_URL, USER, PASS);
               System.out.println("Connected database successfully...");
               System.out.println("Inserting records into the table...");
  
               String sql = "INSERT INTO document (document_id, document_name, format)" +
              "VALUES (?, ?, ?)";
               PreparedStatement preparedStatement = conn.prepareStatement(sql);
               preparedStatement.setInt(1, 1);
               preparedStatement.setString(2, "Test2");
               preparedStatement.setString(3, "Test3");
               preparedStatement.executeUpdate(); 
               preparedStatement.close();  
               conn.close();  
          }catch(SQLException se){
            //Handle errors for JDBC
  
         }catch(Exception e){
            //Handle errors for Class.forName
  
         }
       }
    }
  </code></pre>