[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Capturing System time and storing in mySQL while submitting a form in JSP

Posted on 2004-11-15
6
Medium Priority
?
291 Views
Last Modified: 2010-04-01
Hello,

I developed a form in JSP. This form contains two fields, i.e. text box,text area . These are for entering news title and news description. When i submit the form the system time (submission time) has to be stored in the database. How can i achieve this in JSP?.

At the moment my mySQLl data model contains two columns, i.e. NewsTitle, NewsDescription. And what data type should i use for inserting time of submission in the database.

Please help me in this regard. A snippest of code would be helpful for capturing system time (time of news submission).

Thanks
rams
0
Comment
Question by:ramsin
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
ramazanyich earned 252 total points
ID: 12589167
As JSP is based on Java you can use java.util.Date class. But during inserting data to RDBMS (MySQL) you should convert it to java.sql.Date. And in DB your table should have additional column in type DATETIME. eg:
NewDate DATETIME

<%
java.util.Date curdate = new java.util.Date();  
java.sql.Date dbdate  = new java.sql.Date(curdate.getTime());
PreparedStatement st = ....
st.setDate(dbdate);
%>
0
 
LVL 1

Assisted Solution

by:applejuice
applejuice earned 248 total points
ID: 12614773
Hello, i use the following:

//setup current dates and times
java.util.Date thedatetoday = new java.util.Date();
SimpleDateFormat fulldate = new SimpleDateFormat( "EEE MMM dd HH:mm:ss z yyyy" );
SimpleDateFormat datadate = new SimpleDateFormat ( "yyyy-MM-dd" );  
SimpleDateFormat datatime = new SimpleDateFormat ( "HH:mm:ss" );
String thesubdate = datadate.format(thedatetoday);
String thesubtime = datatime.format(thedatetoday);


Then you can add to mysql database using:

PreparedStatement pStmt = Conn.prepareStatement("insert into databasename values('',?,?)");
pStmt.setString(1,thesubtime);
pStmt.setString(2,thesubdate);
pStmt.executeUpdate();
pStmt.close();

The mysql table needs fields creating as TIME and DATE respectively


Hope that helps,

0
 
LVL 1

Expert Comment

by:applejuice
ID: 13621597
I fancy the points for myself having given a valid answer, with code
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question