Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete record Coreesponding to Date

Posted on 2001-06-20
1
Medium Priority
?
391 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 150 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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

926 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