Solved

Delete record Coreesponding to Date

Posted on 2001-06-20
1
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to see all occupied ports on windows 10 laptop 15 94
jsp insert to database example 2 89
swing controls 2 37
American Express @Work site and Java 4 95
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 …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

739 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