Solved

Delete record Coreesponding to Date

Posted on 2001-06-20
1
365 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now