Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
how to use else statement in the code
shiju nair
Ranch Hand
Posts: 45
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi,
Please have a look at the code.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:employee_details"); PreparedStatement p=null; p=con.prepareStatement("select * from emp_leave_application where approver='"+username+"'"); ResultSet r=p.executeQuery(); while(r.next()) { out.println("data found"); }
Now here how should i use the else statement that if rows are not found then
out.println("no data found");
this is the structure of my database i am using ms-access.
m_emp_no|from_date|to_date|approver|status| ________________________________________ 1002 | 22/9/2008 | 23/9/2008|1003 |pending 1004 | 29/9/2008 | 30/9/2008|1003 |pending 2044 | 15/9/2008 | 16/9/2008|3076 |pending
Please help me .
thanks in advance.
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i tell you some idea, no need to go for else ...
[B]boolean isUser=false;[/B] while(r.next()){ isUser=true;//if rows not found then it wont execute right? out.println("data found"); } then, you just use [B]if(!isUser){ // do your logic }[/B]
Hope This Helps
Ulf Dittmer
Rancher
Posts: 43081
77
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Another possibility would be:
if (r.next()) { do { // ... } while (r.next()); } else { // ... }
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thnaks ULF.. your way is looks GOOD
shiju nair
Ranch Hand
Posts: 45
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks to both of you .
I have solved my query using your code.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
send variable value from one servlet to another servlet for itext pdf
Servet and Jdbc
problem with ResultSet
how to individually get the data in jsp page
Need to split up servlet
More...