Insert Time to database in Java

Description

The following code shows how to insert Time to database.

Example


    /*from   ww  w . j  av  a 2 s  . c o m*/


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Time;

public class Main {
  public static void main(String[] argv) throws Exception {
    Time time = new Time(0);

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial",
        "root", "root");

    String sql = "INSERT child VALUES(?,?)";
    PreparedStatement prest = con.prepareStatement(sql);
    prest.setString(1, "vinod");
    prest.setTime(2, time.valueOf("1:60:60"));
    int row = prest.executeUpdate();
    System.out.println(row + " row(s) affectec)");
  }
}




















Home »
  Java Tutorial »
    JDBC »




Batch
Binary Data
Database
Date Time
Insert
ResultSet
SQL
Statement
Stored Function
Table