Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Inserting date into database

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Inserting date into database

    there is an exception in inserting date into database

    String Fname= request.getParameter("txtfname");
            String Lname= request.getParameter("txtlname");
            String Uname=request.getParameter("txtuname");
            String Pass=request.getParameter("txtpass");
            String Email=request.getParameter("txtemail");
            String Gender=request.getParameter("group1");
            String Add=request.getParameter("txtadd");
            java.sql.Date  sqlDate = new java.sql.Date(new java.util.Date().getTime());
            //out.println(""+Fname+Lname+Uname+Pass+Email+Gender+Add);
            Connection con= null;
            //if(Fname != null && Lname != null && Uname != null && Pass != null && Email != null && Gender != null && Add != null)
            try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con=DriverManager.getConnection("jdbc:odbc:SQL","sa","mith1234");
                String insert="insert into sign_up values(?,?,?,?,?,?,?,?)";
                PreparedStatement ps= con.prepareStatement(insert);
                ps.setString(1,Fname);
                ps.setString(2,Lname);
                ps.setString(3,Uname);
                ps.setString(4,Pass);
                ps.setString(5,Email);
                ps.setString(6,Gender);
                ps.setString(7,Add);
                ps.setDate(8,sqlDate);
               // ps.setDate(9, null);
                int rt= ps.executeUpdate();
                Cookie c= new Cookie("Cuname", Uname);
                response.addCookie(c);
                response.sendRedirect("Home.jsp");
            }
     
            catch(ClassNotFoundException e)
            {
                out.println("Class not found :"+e.getMessage());
            }
            catch(SQLException s)
            {
                out.println("Sql exception: "+s.getMessage());
            }
            catch(Exception ex)
            {
                out.println(ex);
            }
        }



    Exception: Sql exception: [Microsoft][ODBC SQL Server Driver]Optional feature not implemented


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Inserting date into database

    Google the exception..

    You're just lucky I ran into this problem before. The exception returned from the driver isn't very clear what it means "Optional feature not implemented."
    The problem is SQL Server doesn't not support java.sql.Types.DATE. You'll have to use java.sql.Types.TIMESTAMP.
    It took me a long time to figure this out.
    Hopefully this is the cause. Give that a try..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. The Following User Says Thank You to JavaPF For This Useful Post:

    mithcool (July 16th, 2011)

  4. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Inserting date into database

    Thanx friend it did help me. Actually i was getting the above exception and on the other hand the date was inserted into database excluding other request parameter values... anyways timestamp did fix my problem.. Let me know the reason about the above exception....

Similar Threads

  1. same date should entered in another date field
    By shashib09 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 14th, 2011, 08:42 AM
  2. Java Newbie - Sorted Linked List not inserting properly - please help!
    By bubbleboy in forum What's Wrong With My Code?
    Replies: 20
    Last Post: June 17th, 2011, 11:48 AM
  3. Beginner Needs Help Inserting row to table
    By MoniD in forum JDBC & Databases
    Replies: 5
    Last Post: March 10th, 2011, 02:15 PM
  4. Check for duplicates before inserting into database
    By igor0203 in forum JDBC & Databases
    Replies: 1
    Last Post: December 2nd, 2010, 09:04 AM
  5. Inserting Image Help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 22nd, 2010, 12:50 PM

Tags for this Thread