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



Home Answers Viewqa Java-Beginners Getting Computer Date in java

Have Programming Question? Ask it here!
 
 
 


Anthony Maniquiz
Getting Computer Date in java
3 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners


Hi , I want to get the PC Date and insert it to a DB, specifically MSSQL.. Everything in my scriptlet works but this..

String strDate = new Date();

I get this server error, "The type Date is ambiguous".

I've also tried Date date = new Date(); ... but it get's the same error.

Also, I want the date format to come out something like this.. 10-24-2012..

Can anyone help??


Advertisement
View Answers

February 28, 2012 at 5:55 PM


date datatype should be of varchar type.

import java.sql.*;
import java.util.*;
import java.text.*
class  InsertDate{
    public static void main(String[] args){
    try{
        java.util.Date d=new java.util.Date();
        SimpleDateFormat sdf=new SimpleDateFormat("MM-dd-yyyy");
        String st=sdf.format(d);
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );

        Statement pstmt = conn.createStatement();
        String INSERT_RECORD = "insert into person(dob) values('"+st+"')";
        pstmt.executeUpdate(INSERT_RECORD);
        pstmt.close();
        conn.close();
    }
    catch(Exception e){
        e.printStackTrace();
    }
  }
}


February 28, 2012 at 6:03 PM


The package java.util.* and java.sql.*, both are having Date class. Therefore this error occurs. Use classes with their package as well like if you are using Date class of util package then use it as java.util.Date and if you are using java.sql.Date then use it as java.sql.Date.



February 28, 2012 at 6:41 PM


Thanks ! Helped Very Much ! :D



Related Tutorials/Questions & Answers:
Getting Computer Date in java
Getting Computer Date in java  Hi , I want to get the PC Date... but this.. String strDate = new Date(); I get this server error, "The type Date is ambiguous". I've also tried Date date = new Date(); ... but it get's the same error
Get computer name in java
Get computer name in java       We can get the computer name by the java code program. For getting computer name we have used java.net.InetAddress class. We will use static
Advertisements
Date not getting in proper format
Date not getting in proper format  import java.util.*; class Date { public static void main(String[]args) { Date d = new Date(100000000000L); System.out.print("1st date"+d.toString()); } } out put:- 1st date@3e25
getting current date without using system date - Date Calendar
getting current date without using system date  I want to get the current date but the Java code should not get System date as Current date. Pleae help me in getting current date without using system date. thanks in Advance
Getting the current date
Getting the current date     ... date of the system. In this section, through the given program you can get the current date in the proper format (Day/Month/Year). This program shows
computer configuration - Java Beginners
computer configuration  someone posted a code but tha is not working and i am totaly new to java and i hae to submit my project kindly help and send a working code Create a class Computer that stores information about
java with computer network
java with computer network  i feel it's very difficult to use java for network programming. how can i recover this problem?give me any simple example... that explains the java for network programming Overview of Networking through JAVA
computer management - Java Beginners
computer management  Create a class Computer that stores information... to be stored about a single computer is, - Company Name - RAM size... array of 4 objects of Computer class and that takes input for all above
Computer dealer management - Java Beginners
Computer dealer management  Create a class Computer that stores.... The information to be stored about a single computer is, - Company Name - RAM size... ( ) method that creates array of 4 objects of Computer class and that takes input for all
Computer Scince 1015 - Java Beginners
Computer Scince 1015  Write a SavingsAccount class to store the following information related to a bank account: Account number, Password, Branch name, Surnames, First names, Balance The account balance should be able
Getting the Records in PL/SQl between Date Ranges - JDBC
Getting the Records in PL/SQl between Date Ranges  Getting the records Between the Dates in PL/SQL Database by using JDBC and display through JSP
Getting the modification date and time of file or folder in Java
C:\nisha>java GetDirectoryAndFileModifiedTime Enter file or directory name in proper format to get the modification date and time : myfile.txt File name : myfile.txt File modification date
getting random number in java
getting random number in java  getting random number in java Hi... random numbers between 1 to 100 in Java. Though i m new to Java, i have tried many... in my Java application but nothing seems to work. In order to get the random
Getting Started With Java
Getting Started With Java       JDK 6 Tutorial The latest news for the java programmers that the Sun MicroSystems has released the Java SE 6 on Monday December 11.  
Getting A File's Mime Type In Java
Getting A File's Mime Type In Java  Getting A File's Mime Type In Java
Getting date by time
Getting date by time       In this example of creating date using the timestamp value. We can... DateByTime.java C:\DateExample>java DateByTime New Date:=Sun Jan 25
Java Date conversion - Date Calendar
Java Date conversion  How do I convert 'Mon Mar 28 00:00:00 IST 1983' which is a java.util.Date or String to yyyy/MM/dd date format in sql
How to find version of Java installed on my computer? - Java Beginners
How to find version of Java installed on my computer?  How to get... with many more new features.How to find version of Java installed on my computer?To find out the version of Java installed on your computer, just type Java
Getting Previous, Current and Next Day Date
Getting Previous, Current and Next Day Date   ... previous, current and next date in java. The java util package provides... the previous, current and next date to Date() constructor of java.util package
Installing Java (JDK 7) on Windows 7 Computer Video Tutorial
Installing Java (JDK 7) on Windows 7 Computer Video Tutorial
Getting environment variable value from java
Getting environment variable value from java  Getting environment variable value from java
Getting 404 errors - Java Beginners
Getting 404 errors  Dear experts, I have embedded a login page inside my landing page - home.jsp. So, at the right-hand column of my page, I use the below codes:- Login
Mysql Date To Java Date
Mysql Date To Java Date       Mysql Date To Java Date retrieve the records from Mysql and display the date in java. Understand with Example The Tutorial illustrate an example from
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
java yesterday - Date Calendar
java yesterday  Afternoon,Yesterday i have a question that how to make date sustract, the result is to make 1 month and 1 day like this, right. now how about 1 year and 1 month? And Can help me to using Date Calender what
Getting Current Directory from java - Java Beginners
Getting Current Directory from java  I'm designing an application in linux where i need to get the current directory of my java file... I'm using...://www.roseindia.net/java/java-get-example/get-CWD.shtml http://www.roseindia.net/java
java Date - Java Beginners
java Date  Dear sir I have an assignment, It is .. "Develop Date class in java similar to the one available in java.util package.Use JavaDoc..., Try the following code: public class Date { private final int month
Java Date - Java Beginners
Java Date  I have to find the previous date's beginning time and end time in the long milliseconds format. for example today date is '23rd April... main(String[] args) { Date now = new Date(); DateFormat df   Hi friend
java - Date Calendar
Java convert string to date  I need an example in Java to convert the string to date.  Convert string to date formatimport... str_date="04-04-2008"; DateFormat formatter ; Date date
date picker - Java Beginners
date picker  sir i need code for date picker in java swing because for Embedding in my project plz sir
Display Date - Java Beginners
Display Date  Plz send me sample java program that display day, date... to display day,date,year and current time. import java.util.*; class DateExample { public static void main(String[] args) { Date date = new Date
Date Java - Java Beginners
Date Java  I'm using the eclipse software and I get an error for my...: public class Date { private int month; // 1-12 private int day; // 1-31... for day. public Date( int theMonth, int theDay, int theYear ) { if ( theMonth
Java programme - Date Calendar
Java programme  Can you provide me the coding for Date class provided by java util package
Java Date Example
Java Date Examples       Getting astrological sign according to birth date In this section we will be getting the astrological sign according to the inserted birth
Parsing date in Java
Parsing date in Java  How can i parse the date in Java in a simple format..?   SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy
java format date
java format date  Hi, How can I format the date in the following...) { Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); String formattedDate=sdf.format(date
date - Java Beginners
date  1.Write a program to check input date is valid or not using java(value must be given by user)  Hi Friend, Try the following code... DateValidation{ public boolean isValidDate(String date){ SimpleDateFormat sdf = new
java date - Java Beginners
java date   Hi, Please observe the below code: import... is "login" the name,date,time is automaticaaly inserted into the database . My doubt is iam storeing system date and system time but i want to store i server
java yesterday - Date Calendar
java yesterday  And how to make date format DD/MM/YYYY,thank's ... static void main(String args[]){ Date todaysDate = new java.util.Date... formattedDate = formatter.format(todaysDate); System.out.println("Formatted date
ask java - Date Calendar
but in java i found too but i can't to join in another frame. And i want to ask how to subtract a date, ex:i work since 2008/09/01 so i'am work until now 1 month 10... { public static void main(String[] args) { Date date = new Date
Date picker in Java Swing
Date picker in Java Swing  Hello Sir, Sir ,I am in need of Time Picker just like the Date picker available in java Swing. Kindly... link: Java Date Time Picker Example   Hello Sir, Thank
java - Date Calendar
java   Using java how can i change the date format of the system from mm/dd/yy to dd/mm/yy. The code which i wrote is changing the format only on the console and not on the system's control panel.Can you suggest me anything
date problem - Java Beginners
date problem  how to extract day,month,year hours ,second from a string date. Examples: String dat ="200912202934" from this string extract month ,year,date,hours,minute Please help me. Thanks in advance Sushil 
Java String To Date
Java String To Date In this section you will read about how to convert... be convert into java.util.Date. Java string to date convert explains the conversion of Java string written into the specified format to a Java date object
java again - Date Calendar
java again  I can't combine your source code yesterday, can you help... : Date now : jtextfield1 //jTexfield1=date now //we enter ,then result in jTextfield2 Date work : jtextfield2 This my Source
date and time in awt(java)
date and time in awt(java)  sir, do you have an example of date in awt java which can be view over a textfield.   Display time in JTextField import java.util.*; import javax.swing.*; import java.awt.event.*; public
Java Date
The Java Date class allows the developers to manipulate date and time from within the Java program. The Java Date class is very useful... the date with the Java Date or calendar class.   The Java Date class
getting unique value from java.util.random - Java Beginners
getting unique value from java.util.random  i am doing a shopping cart project. In that i need to display some product randomly in the home page..., but the value which i am getting contains duplicate values and it is not unique, my
Computer Networks
Computer Networks  The IPV4 packet has arrived wtih first few hexadecimal digits as 0X45000028000100000102. How many hopes will this packet travel before being dropped
 

 

 

DMCA.com