Solved

Delete record Coreesponding to Date

Posted on 2001-06-20
1
372 Views
Last Modified: 2010-04-16

I wrote a Java program to Store VoiceMail and Delete that record using SQLServerBridge..I used preparedStatement to insert and Dete it..I used timestamp to Insert and delete the record..When I insert there is no problm..But when I tried to delete it will not return any compile or runtime error ..But the data is not deleted..Pls help me to delete that record ...I herewith attach that code also..
Pls Check it...Thanx

                             regards
                                         Sujeesh

//Connection to SQLServer.... Bridge....DSN name-->Sqldsn
                         Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
                         String url = "jdbc:odbc:Sqldsn";
                         Properties p=new Properties();
                          p.put("user","sa");
                          p.put("password","");
                          p.put("serverVersion","Sql7");
         
          //Insert values to a table 'VoiceMail' Using preparedStatement whch includes  a VoiceFile and timeStamp

                         Timestamp ts=new Timestamp(System.currentTimeMillis());
                   
                         String filename = "c:\\testing.mp3";
                      File f = new File(filename);
                         FileInputStream fis = new FileInputStream(f);
                         int available=fis.available();
                         System.out.println("Available=="+available);
                         Connection cn = DriverManager.getConnection(url,p);
                         PreparedStatement psw = cn.prepareStatement("INSERT INTO  VoiceMail VALUES "+ "(?,?,?,?,?)" );
                         psw.setString(1,"sujeesh");
                         psw.setString(2,"Renjith");
               
                       psw.setTimestamp(3,ts);
     
               psw.setString(4,"Test");
               psw.setBinaryStream(5,fis,available);//1,fis,(int)f.length()
            psw.executeUpdate();
               System.out.println("Success");

               psw.close();
                              Statement stmt  = cn.createStatement();
               ResultSet rs = stmt.executeQuery("Select VoDate from VoiceMail");
               rs.next();
               rs.close();
               stmt.close();
     //Delete the same record which I inserted before.....

               PreparedStatement psw1 = cn.prepareStatement("DELETE FROM VoiceMail WHERE  VoDate = ?");
               psw1.setTimestamp(1,ts);
               System.out.println("Prepared Statement="+psw1.toString());
               psw1.executeUpdate();
               psw1.close();
0
Comment
Question by:sujeeshlal
1 Comment
 

Accepted Solution

by:
darrenc earned 75 total points
ID: 6325841
What I think migh be happening is that there may be a problem with the date format being used when you say psw1.setTimestamp(1,ts).

Here are two things I would try:
1. I think the return value of psw1.executeUpdate() is the number of records affected.  I'll bet the return value is 0.
2. Rewrite the PreparedStatement into a standard statement and format the date into your database-specific date format.
eg. PreparedStatement psw1 = cn.prepareStatement("DELETE FROM VoiceMail WHERE  VoDate = '31-12-2001' ");
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
micro services vs rest web services 16 107
java stored proc example 9 32
Android development question 2 38
Glassfish admin console not working 1 16
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question