How to Store Date

Ads

 
 

Share on Google+Share on Google+

shweta
How to Store Date
1 Answer(s)      7 years ago
Posted in : Java Beginners
How to Validate date in JTextField ,How I can Store it in Aceess Databse,
and I want to set Last Date of Admission,if Last date of admission is equal to current date then i want display Today is Last date of Admission ,if Current Date is Over than Last Date then I want to Disable All Admission Entry Form Contents.
Plz Help Me Sir Its Urgent sir.
Ads
View Answers

April 8, 2010 at 4:16 PM


Hi Friend,

1)Insert Date

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
class InsertDate extends JFrame{

InsertDate(){
JLabel l=new JLabel("Enter Date (dd/MM/yyyy):");
final JTextField text=new JTextField(15);
JButton b=new JButton("Insert");
JPanel p=new JPanel(new GridLayout(2,2));
p.add(l);
p.add(text);
p.add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String date=text.getText();
if(isValidDate(date)){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement ps = con.prepareStatement("INSERT INTO InsertDate(ID,lastDate) VALUES(?,?)");
ps.setString(1,"8");
ps.setString(2,date);
ps.executeUpdate();
System.out.println("inserted");
}
catch(Exception e){
System.out.println(e);
}
}
}
});
add(p);
setVisible(true);
pack();
}
public boolean isValidDate(String inDate) {

if (inDate == null)
return false;
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
dateFormat.setLenient(false);
try {
dateFormat.parse(inDate.trim());
}
catch (ParseException pe) {
return false;
}
return true;
}

public static void main(String[] args){
InsertDate insert=new InsertDate();
}
}

2)Check Status

import java.sql.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.text.*;
import java.awt.event.*;

class CheckStatus{
public static void main(String[] args) {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("Select lastDate from InsertDate where id='8'");
String ld="";
if(rs.next()){
ld=rs.getString("lastDate");
}

String lastDate=ld.substring(0,10);
System.out.println(lastDate);
java.util.Date d = new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String todayDate=sdf.format(d);
System.out.println(todayDate);
java.util.Date date1 = sdf.parse(lastDate);
java.util.Date date2 = sdf.parse(todayDate);
if(date1.equals(date2)){
JOptionPane.showMessageDialog(null,"Today is Last date of Admission ");
}
else if (date1.before(date2)){
JOptionPane.showMessageDialog(null,"Admission is Over");
}
}
catch(Exception e){
System.out.println(e);
}
}
}

Thanks

Ads









Related Tutorials/Questions & Answers:
How to Store Date - Java Beginners
How to Store Date  How to Validate date in JTextField ,How I can Store it in Aceess Databse, and I want to set Last Date of Admission,if Last date of admission is equal to current date then i want display Today is Last date
To store date - JSP-Servlet
the method. And send the actual query to store the date also. With lots of thankzs.....   Hi friend, Code to store date in database...To store date  Hai friends, I want the format to store
Advertisements
Jsp Code to store date in database - JSP-Servlet
Jsp Code to store date in database   Hi, Can u give me jsp code to store current date in to database. Thanks Prakash
How to store an image in database
How to store an image in database  Hi........... How to store an image in postgresql using a query. I mean tell me the way to store an image using datatype. I am using the datatype bytea but tell me how to insert the image
How to store image into database
How to store image into database  Hi, all I want to store image into database using Java. Can anyone help me that how can i store image into database... through the following link How To Store Image Into MySQL Using Java
how to write store procedure in sql
how to write store procedure in sql  How to write a store procedure in SQL Server
How to compare date in Java?
How to compare date in Java?  Hi, How to compare date in Java? Thanks   Hi, Check this example Date Comparison. Thanks
How to display date in JSP?
How to display date in JSP?  How to create a simple JSP program which displays date on the page? Thanks
How to store url path?
How to store url path?  Image is stored in physical directory like this String file = "C:/xampp/htdocs/jobqueen/" + username + createTimeStampStr() + ".PNG"; this physical directory is working fine but I want store in url
how to store,retrieve,modify the data
how to store,retrieve,modify the data  hello sir ,how to store,retrieve,modify the data using the swing please help me
store current system date in to database - Development process
store current system date in to database  Hi,this is my code . here iwant to store current system date in to database and want to store subdept..."].elements["combo2"].options.length=0; for (var i=0;i<% java.util.Date date
How to Convert String to Date?
How to Convert String to Date?  Hi, I am new in Java and learning the Date manipulation in Java. I have to write a program in Java which converts... have to convert it to Date object. Tell me How to Convert String to Date? Thanks
how to add date and change date in java - netbeans
how to add date and change date in java - netbeans  I need to code use to increase date How to get date after 30 days using netbeans
how to get current date without system date
how to get current date without system date  is there any possiblity to get current date instead of system date in Java, as i dont want to change date in program and if i change date in OS automatically change in program also
How to display date in JSP?
How to display date in JSP?  How to create a simple JSP program which displays date on the page? Thanks   Hi, You should import...; Then use the following code to print the current date: <%= new java.util.Date
How to store url path in file ?
How to store url path in file ?  Hi, How to store url path in file ? this my program public class Image implements Runnable..."; This is store phiscal directory but i want store url path like
How to Store Image using JSF
How to Store Image using JSF  Hi How to upload images in db. using jsf. For jsf photo uploading .. I used this one code for upload image.. But this code haven't option to upload any images . i want to store image in db
how can we store the encrypted passwaord in swings?
how can we store the encrypted passwaord in swings?   how can we store the encrypted passwaord in swings
How to capture video and then how to store it in mobile memory
How to capture video and then how to store it in mobile memory  Hello there, I'm developing a mobile application where i'm capturing video from... to store it in mobile memory. so plz tel me ow to do it. if you give example code i
How to display current date in textbox - Date Calendar
How to display current date in textbox  Hi guys, I'm really need your... Date(); var month = currentTime.getMonth() + 1; var day...(); document.forms[0].date_stamp.value = day + "-" + month + "-" + year
how to store jtable value in multidimensional array?
how to store jtable value in multidimensional array?   i want to store the value of jtable in multidimensional array,with type double. how to store jtable value in multidimensional array
how to store jtable value in multidimensional array?
how to store jtable value in multidimensional array?   i want to store the value of jtable in multidimensional array,with type double. how to store jtable value in multidimensional array
How to store JComboBox item into database
How to store JComboBox item into database   import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import
how to store dynamic array in hidden field in javascript?
how to store dynamic array in hidden field in javascript?  I have... to store it in a hidden field for passing it to the jsp page. so any one help me in how to store it in hidden field
how to store and then immediately retrieve when store the image into database?
how to store and then immediately retrieve when store the image into database?  how to store and then immediately retrieve when store the image into database?   Here is a jsp code that insert and retrieve image from
How to use Date Picker iPhone
How to use Date Picker iPhone  Hi, I am beginner in mobile Application platform. I want to develop a small application in iphone platform to Show current date and display alert view message. So, how to define the date picker
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java and trying to write a program to get the current date. How to get the current date in Java? Thanks   Hi, Check the tutorial: Java program to get current date
how to find the given date is sunday
how to find the given date is sunday  how to find the given date...[] args){ Date date= (new GregorianCalendar(2010, Calendar.SEPTEMBER, 20)).getTime...=f.format(date); if(day.equals("Sunday")){ System.out.println("20-09-2010
How to calculate Date Difference in Java?
How to calculate Date Difference in Java?  Hi, I have two dates variable. How to calculate Date Difference in Java? Thanks   Hi, You can use the Calendar class for calculating the date difference in Java. Get data
How to get max date in Hibernate?
How to get max date in Hibernate?  Hi, Tell the code to get the max date in Hibernate? Thanks   Hi, You can use the projection in Hibernate for getting the max date. Here is example code: Projections.max("addmision
How to retrieve the ISO Date in PHP?
How to retrieve the ISO Date in PHP?  Hi, I am a beginner in PHP programming language. I have a query how to retrieve the ISO Date in PHP Language. Can any one suggest any reference for this. Thanks

Ads

 
Advertisement null

Ads