Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [JSP] Date ...

  1. #1

    [JSP] Date ...

    Ciao a tutti,
    ho un problema che mi fa sentire un po' cretino

    Voglio recuperare la data attuale, o cercato su google ma tutti i metodi che ho trovato utilizzano Date e anche se importo java.util.Date oppure uso direttamente java.util.Date non va

    An error occurred at line: 9 in the jsp file: /prove/prova_ins.jsp Generated servlet error: The type Date is ambiguous An error occurred at line: 9 in the jsp file: /prove/prova_ins.jsp Generated servlet error: The method executeUpdate(String) in the type Statement is not applicable for the arguments ()
    Chi mi aiuta ?

    Grazie mille ...
    _____________

    Bruce

    www.palestracft.it

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: [JSP] Date ...

    Originariamente inviato da Bruce O'Canaan
    Voglio recuperare la data attuale, o cercato su google ma tutti i metodi che ho trovato utilizzano Date e anche se importo java.util.Date oppure uso direttamente java.util.Date non va
    An error occurred at line: 9 in the jsp file: /prove/prova_ins.jsp Generated servlet error: The type Date is ambiguous An error occurred at line: 9 in the jsp file: /prove/prova_ins.jsp Generated servlet error: The method executeUpdate(String) in the type Statement is not applicable for the arguments ()
    Il perché lo si evince dalla indicazione del executeUpdate(), ovvero stai usando JDBC e quindi il package java.sql.

    Bene, esiste una classe Date in java.sql ed esiste una classe Date in java.util!!! E java.sql.Date estende java.util.Date.

    Se importi:
    import java.sql.*;
    import java.util.*;

    Il solo nome "Date" è "ambiguo". Hai 2 possibilità:

    a) Mettere nel codice il nome completamente qualificato es.: java.sql.Date d = new java.sql.Date(......

    b) Mettere un "single type import" es.:
    import java.sql.*;
    import java.util.*;
    import java.sql.Date;

    Quindi ora il solo nome Date fa riferimento a quello in java.sql.

    Nota che in java.sql.Date l'unico costruttore utile è quello che riceve un long, quindi potresti passargli il valore di System.currentTimeMillis().
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.