Author
preparedstatement
pavan sharma
Greenhorn
Joined: Dec 19, 2006
Posts: 21
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
Joined: Mar 06, 2001
Posts: 13459
posted Jan 08, 2007 23:41:00
0
Moving to the JDBC forum. Dave
karthikeyan Chockalingam
Ranch Hand
Joined: Sep 06, 2003
Posts: 259
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.
http://www.skillassert.com
Muhammad Saifuddin
Ranch Hand
Joined: Dec 06, 2005
Posts: 1318
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 ]
Saifuddin..
[Linkedin] How To Ask Questions On JavaRanch My OpenSource
pavan sharma
Greenhorn
Joined: Dec 19, 2006
Posts: 21
Still i have problem..... Class.forName("oracle.jdbc.driver.OracleDriver"); Connection c = DriverManager.getConnection("jdbc racle: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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26496
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.
[Blog ] [JavaRanch FAQ ] [How To Ask Questions The Smart Way ] [Book Promos ]
Blogging on Certs: SCEA Part 1 , Part 2 & 3 , Core Spring 3 , OCAJP , OCPJP beta , TOGAF part 1 and part 2
pavan sharma
Greenhorn
Joined: Dec 19, 2006
Posts: 21
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
Joined: Dec 06, 2005
Posts: 1318
It seems like oracle driver not supported this method.. what version are you using? suggestion: try download a more recent version of Oracle driver.
subject: preparedstatement