
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??

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();
}
}
}

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.

Thanks ! Helped Very Much ! :D
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.