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 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
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 write store procedure in sql
how to write store procedure in sql  How to write a store procedure in SQL Server
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
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 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 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 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 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 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 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 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 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 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 store and retrieve image from database in JSP?
How to store and retrieve image from database in JSP?  Hi, In one of my application I have to store and then display the image in JSP. How to store and retrieve image from database in JSP? Thanks   HI, You can use
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
store
store  i want to store data in (.dat) file format using swing and perform operation on that insertion,deletion and update
store
store  hi i want store some information in my program and use them in other method. what shoud i do
how to store data in XML file - JSP-Servlet
how to store data in XML file  hi i have to store the data for example user id and password in a xml file the input userid and password will be coming from jsp middle ware servlet how to do that?   Hi friend
how to store/retrieve doc file - Java Beginners
how to store/retrieve doc file  i want to wirte a code that stores/ retrieves .doc files to the mysql database using jsp pages... can anyone help me with the code?  Use this stuff inside your jsp page for store file
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 a dynamic values - JSP-Servlet
how to store a dynamic values  Dear sir, i have a ArrayList in that i have stored a values from a excel sheet specified column values and i have one string that is as follows Dear ~2 , Your cl is ~3 ,el is ~4
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using jsp   Here is a jsp code that insert and retrieve image from mysql