Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preparedstatement

 
pavan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code for example..........


sqlstmt = "UPDATE CATEGORIES SET SUB=? , HAS_SUB=? WHERE ID=?";
pstmt = conn.prepareStatement(sqlstmt);
pstmt.setString(1,subcatids);
pstmt.setString(2,"Y");
pstmt.setString(3,selsubcat);

pstmt.executeUpdate();


There is no problem in code...and query updated successfully...

but here i want to print the 'sqlstmt' statement....to know what exactly
query contain in place of palce holder (?)...

how can print it with preparedstatement....

Reply me ASAP

Thanks
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum.

Dave
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first ? will be replaced with the value of subcatids, second with Y and the third with the value of selsubcat.

When we say pstmt.setString(2,"Y");, 2 represents the second ? in the PreparedStatement from left to right.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pavan sharma:

but here i want to print the 'sqlstmt' statement....to know what exactly
query contain in place of palce holder (?)...
how can print it with preparedstatement....


here is an example of using the ParameterMetaData interface to retrieve information about parameters in preparedstatement.

I hope it makes you more clear on that..
[ January 09, 2007: Message edited by: Saif uddin ]
 
pavan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still i have problem.....

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c = DriverManager.getConnection("jdbcracle:thin:@10.100.204.249:1521:TSS","TSSDB","TSSDB");
PreparedStatement ps = c.prepareStatement("SELECT * FROM M_LEVEL_1");

ParameterMetaData pmd = ps.getParameterMetaData();


problem to call :- getParameterMetaData();
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pavan sharma:
problem to call :- getParameterMetaData();

What's the problem? You get a compiler error? The code throws an exception? The program crashes?

Please provide some more details so we can help.
 
pavan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got this error when calling getParameterMetaData()

Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatement.getParameterMetaData()Ljava
at test.main(test.java:21)
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like oracle driver not supported this method..
what version are you using?

suggestion:
try download a more recent version of Oracle driver.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic