Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Insert date into database using JSP
Sponsered Links
Categories
Sponsered Links

Insert date into database using JSP

This section demonstrates you how to insert date into the database table.

<%@page import="java.sql.*,java.util.*"%>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
 Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
 PreparedStatement pstmt = conn.prepareStatement("insert into myDate(id, myDate) values(?, ?)");
    pstmt.setInt(1, 32);
    java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
    pstmt.setDate(2, sqlDate);
    pstmt.executeUpdate();
    out.println("Date is successfully inserted");
}
catch(Exception e){
System.out.println(e);
}
%>

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved