Solved

Delete record Coreesponding to Date

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
table example 4 32
expectj telnet failing 5 45
spring jars download 1 35
learn programming 8 42
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

828 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