Forums Register Login

servets and jdbc connectivity

+Pie Number of slices to send: Send
I am trying to create a login page asking user for username and password, once submitted i am passing this info to servlet which will connect to database and check if login id and password is correct or not... here is my servlet code:


I know i should be using post instead of get ...but i was having some problem in using that that i ll resolve later... as of now now my problem is that the above code is conneccting to database but not giving the desired output... ie if i remove line
" if (username.equals(rs.getString("name"))) "
(in while statement) it is giving names of all users in database ... but no output otherwise... please help...
+Pie Number of slices to send: Send
You login code is incorrect. You must create the SQL statement based on the input data (user and pass) like this:

+Pie Number of slices to send: Send


Change it to
+Pie Number of slices to send: Send
thanks both of you for replying.. I made the changes you said and here is my code :

But now it is showing no output not even this line is executing (line no 29)
"p.println("<b><h1>hello before while "+user+"</h1>");"
please help...
+Pie Number of slices to send: Send
 

arjita mahajan wrote:


How do you expect the above query to execute? It should be

arjita mahajan wrote:
But now it is showing no output not even this line is executing (line no 29)
"p.println("<b><h1>hello before while "+user+"</h1>");"
please help...


In your code, line no.29, doesn't show this.. Have you posted the correct code?

Also, initially, variable flag is set to 0, and where is this flag assigned a new value like 1 or any other value? what's the use of checking if(flag==0) when the flag is not at all set after its initialized to 0? Its always going to be true..

EDIT:

arjita mahajan wrote:


This also is not a recommended approach, use e. printStackTrace(); this gives very useful information about exceptions, why just take out message, when we can get a detailed cause of the exception..

P:S: Accessing Database from servlet? not at all a good idea/design, also, emitting HTML tags from servlet also is not a good idea, you should use JSP's for this.
If you have started learning now, start with good practices
+Pie Number of slices to send: Send
thank you all for help, my problem is solved.
P.S: yes , its true that i am new to advance java, i didn't get the reason to use jsp when during compilation it is converted to servlet (what i have read) and web container can get response through servlets only. I am suppose to create a website using java, any help is appreciated , thanks in advance
1
+Pie Number of slices to send: Send
 

arjita mahajan wrote:i didn't get the reason to use jsp when during compilation it is converted to servlet (what i have read) and web container can get response through servlets only. I am suppose to create a website using java, any help is appreciated , thanks in advance..


Why do you write Java code, when computer understands only machine level language? You can directly program in Machine Level Language.
Wish you best of luck for creating a website using servlets (without JSP's)..

Please go through the basics of JSP's then you will come to know, why JSP (View Layer in general, can be jsp or any other thing) play a very important role in any JEE application development..
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1134 times.
Similar Threads
How to separate Business Logic from the servlet
problem with while loop when ResultSet.next() is called
connectivity to databse through oracle 10g
SessionServlet and Login.jsp
about hidden from fields
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:54:09.