Home Answers Viewqa Java-Beginners Getting Computer Date in java

 
 


Anthony Maniquiz
Getting Computer Date in java
3 Answer(s)      a year 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??

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 Pages:
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
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
computer manufacture case study
computer manufacture case study  Computer Manufacturer Case Study BNM is an upcoming computer manufacturer. The company was making a mark... Wireless Mouse 4790 Lotus Notes 6000 Wireless Keyboard 9482 Sun Java Communications
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 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 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
Getting Stated with JDBC
Getting Stated with JDBC In this Getting Started with JDBC tutorial, we... driven Java applications. After completing this tutorial you will able to understand the JDBC concept and develop simple JDBC based Java programs
Remember me on this computer (via cookies) in jsp servlet
Remember me on this computer (via cookies) in jsp servlet  Remember me on this computer (via cookies) in jsp servlet   Hi, Here... of setting the cookies: <%@ page language="java" import="java.util.*"%> <
Date format - Date Calendar
Date format  Hi All, I am getting a date from database as a format 2010-15-07.I need to change it to 07/15/2010 and display it on my date field.Every time i need to check the format of the date field and make sure the correct
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
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
Date prorblem
into string filed in java code. once the date is available in filed ( of type String... = tokens[8]; .... (the date from source into local java filed...)+"'}); when date filed DATEADDED is blank, I am getting the error
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
Computer shop mangerment
of it. Part B Develop array based java program to help a local computer shop...Computer shop mangerment   Part A You are supposed to write a class Computer to stores the computer id, description, brand, price, speed and another
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 Exception
Getting Exception  How to get exception from commented code in java
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 the emplo
getting the emplo   I have one table "EMPLOYEEMASTER" contains 'emp... kumar i want the sql statement for getting like emp id date ------ ---- 1 21/03/2011 1 22/03/2011
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
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
Getting time in Milliseconds
;java GetTimeMilliseconds New Date:=Fri Oct 10 13:26:49 GMT+05:30 2008... Getting time in Milliseconds       In the previous examples of Date class we have created
Hibernate Getting Started
assuming that Java is installed and configured on your computer. MySQL... Hibernate Getting Started       Hibernate Getting Started In this Hibernate Getting
Getting NumberFormatException
Getting NumberFormatException  Hello Sir, I'm using Integer.parseInt(String str) function which returns a NumberFormatException(Unknown source). I.... I used the same type of code in a simple .java program but when I.m using
Getting an error :(
Getting an error :(  I implemented the same code as above.. But getting this error in console... Console Oct 5, 2012 10:18:14 AM... was not found on the java.library.path: C:\Program Files\Java\jre1.5.007\bin;.;C:\Windows
Java Date
Java Date      ... are going to compare two date objects in Java programming language. For comparing...;  Getting date by time In this example of creating
JSP Tutorials, Getting started with JSP
Getting started with JSP The JSP getting started tutorial will help you... to know about JSP. Java Server Pages or JSP for short is the part of Enterprise Java technology for developing the dynamic web application using Java. JSP is good
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
Java program to get current date now
Java program to get current date now   ... date at present now. We have used Calendar class for getting the current date... C:\javaexamples>java GetDateNow Now the date is :=> 2008/Oct/18
Computer Architecture and Programming Languages
Computer Architecture and Programming Languages CPU - Central... programs and data. IFSM 310 is an entire course about computer..., C, C++, Java, C#, ... Human writes "source program". It's translated
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 Error - Development process
Getting Error   Hi , i am getting error while executing this code. I just want to store date in to database. Dont mistake me for repeated questions... fields id : number myDate : Date/Time Service_no : Number UserName : Name
Date Next and Previous - Java Interview Questions
Date Next and Previous  In the example given here, DATE is displayed in DD/MM/YYYY format. Can anybody send me the code for getting DATE in MM/DD...(String[] args){ try { String str_date="04/04/2008"; DateFormat
Getting mysql table in textbox
Getting mysql table in textbox  how to get mysql table values into textbox in java using ajax and servlets
Not getting desired output while button is pressed in java applet program
Not getting desired output while button is pressed in java applet program ..."); L2.setBounds(200,30,250,20); Label L3=new Label("Date...("Paid Date................................................."); L17.setBounds
call another computer in LAN (no internet acces)
call another computer in LAN (no internet acces)  Any idea how to develop a java application that makes VOIP calls inside an isolated (without internet access) network? Is there any (free) software solution for my problem? Thank
date - Date Calendar
date   hi, sir i am doing student details project in swing but i am not getting current date in jtextfield in date it is giving ambigious error... label=new JLabel("Current Date: "); JTextField text=new JTextField(15
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
Date limit on Dojo Date picker - Date Calendar
this validation by getting value from date picker text box or server side also, but I...Date limit on Dojo Date picker  Hi all, I am using dojo for date picker in my project. When user click on date text box, date picker will pop up
Date Formay - Date Calendar
Date Formay  Sir, How to comapare two different date format in java.  Hi friend, Code to compare two different date import...)) System.out.print("Current date(" + new SimpleDateFormat("dd/MM/yyyy"). format
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me...(JspServletWrapper .java:374
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me...) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper .java:374
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.