Solved

JDBC & Prepared Statements

Posted on 2004-10-14
14
177 Views
Last Modified: 2010-03-31
Hi there,

I have a strange problem ..iam unable to figure it out any help will be highly appreciated..I have a database with around 80 tables Iam doing something like

main()
{ PreparedStatement pStmt = null;
try
{
Connection conn = DatabaseConnectionPoolMgr.getConnection();
deleteTablesInternal(conn);
deleteSomeTables(conn);
String sSql = "Delete from demo where demoid=10";
pSmt = conn.prepareStatement(sSql);
pStmt.execute();
pStmt.Close();
System.out.println("After deleting from demo");
}
catch(Exception e)
{
e.printStackTrace();
throw e;
}
finally
{
if(conn!= null)
  conn.close();
if(pStmt != null)
  pStmt.close();
}

}
In deleteTablesInternal() iam deleting some tables using preparedStatement & in deleteSomeTables() also, iam doing the same thing, finally iam deleting from the demo table which is the last table... My problem is the statement "After deleting from demo " is being displayed but the data is not deleted from demo table, all other tables are working fine...Iam using oracle9i as the database, iam in a dilemma & unable to figur it out whether its a database problem or jdbc problem. Any help wil be highly appreciated. thanxs in advance.

*Satish
0
Comment
Question by:satishAnanthuni
[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
14 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 125 total points
ID: 12316472
Sure you have entries for which demoid=10?
0
 
LVL 92

Expert Comment

by:objects
ID: 12316477
check that rows exist with demoid=10
the return value from an update will tell you how many rows were affected.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12316480
You could try executeUpdate() instead of execute()
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 37

Expert Comment

by:zzynx
ID: 12316483
>>the return value from an update will tell you how many rows were affected.
If you use executeUpdate()
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 12321606
Hi satishAnanthuni,

There is no need to use a PreparedStatement in this case, not that it should matter.

Try this:
Statement pStmt = null;
try
{
Connection conn = DatabaseConnectionPoolMgr.getConnection();
deleteTablesInternal(conn);
deleteSomeTables(conn);
String sSql = "Delete from demo where demoid=10";
pSmt = conn.createStatement();
pStmt.executeUpdate(sSql);
pStmt.Close();
System.out.println("After deleting from demo");
}


Cheers!

\tt
0
 

Author Comment

by:satishAnanthuni
ID: 12336349
Hi All,

Its still confusing, there is one record in the demo table with demoid = 10 & the executeUpdate() returns me 1 but somehow, the record still exists in the database..


*Satish
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 12336358
If its returning 1 then it is deleting it.
Are you sure you're not inserting it again later, or checking the wrong database/table?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12336554
>> executeUpdate() returns me 1 but somehow, the record still exists in the database
Rather impossible.
>> Are you sure you're not inserting it again later, or checking the wrong database/table?
Better double check that
0
 
LVL 92

Expert Comment

by:objects
ID: 12336581
zzynx,

really no need to repeat everything I said.
0
 

Expert Comment

by:rickychow
ID: 12345124
i found that u haven't commit, did u do the commit?

conn.setAutoCommit(false);
deleteTablesInternal(conn);
deleteSomeTables(conn);
String sSql = "Delete from demo where demoid=10";
pSmt = conn.prepareStatement(sSql);
pStmt.execute();
pStmt.Close();
System.out.println("After deleting from demo");

conn.commit();
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12544842
Proposal: split objects - zzynx
0

Featured Post

Industry Leaders: 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
pagenation logic how it is working in my code 1 82
ejb entity bean example 2 59
Why doesn't this text field show up on my Applet frame? 2 43
jmeter usage 4 68
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
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 …
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…
Suggested Courses

752 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