Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Ragini Shukla
ddddd
1 Answer(s)      5 years and 11 months ago
Posted in : Java Beginners



Advertisement
View Answers

September 27, 2008 at 11:40 AM


Hi friend,

Code to insert the date in database :

<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<html>
<%
Connection con=null;
PreparedStatement pstatement = null;
String url = "jdbc:mysql://localhost:3306/";;
String dbName = "file_upload";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try{

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url+dbName,userName,password);
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);


String strDateNew = sdf.format(now) ;




String queryString = "INSERT INTO file_tbl set file_date='"+strDateNew+"'";

//out.println(queryString);

pstatement=con.prepareStatement(queryString);


val = pstatement.executeUpdate();

if(val>0)
{
%>
<br><br>
<b><%=strDateNew%> Inserted into Database .</b>
<%
}


}
catch(Exception e)
{}
}
%>
</html>


For read more information :
http://www.roseindia.net/jsp/fileupload.shtml

Thanks



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com