JSP connection to database

Reply

Join Date: Feb 2005
Posts: 11
Reputation: nelly_1005 is an unknown quantity at this point 
Solved Threads: 0
nelly_1005 nelly_1005 is offline Offline
Newbie Poster

JSP connection to database

 
0
  #1
Apr 29th, 2005
hi guys

hope you can help

well im tryin to connect my jsp to my database, im uisng tomcat 5 and have stored the MS access database in my ROOT folder.

i have created a User DNS, and have sdk 1.4.2_08 installed

Problem is im not sure what to do now??

do i have to install a sun driver? if so how?

and finally how do i connect to teh database?

Please help thanks! x
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 8
Reputation: adityabakle is an unknown quantity at this point 
Solved Threads: 0
adityabakle adityabakle is offline Offline
Newbie Poster

Re: JSP connection to database

 
0
  #2
May 1st, 2005
Hi nelly

No need to do much
I hope u are aware of JDBC-ODBC Driver and they are supported by sdk1.4

First create a DSN using ODBC in control pannel
later for JSP to connect to Database

use the following code

<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:<DSN name>")
%

provide DSN name after the second colon.
In this way you are connected to your data base and you can futher query your database using statement object .

For futher help
mail adityabakle@gmail.com
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: amrita.r is an unknown quantity at this point 
Solved Threads: 0
amrita.r amrita.r is offline Offline
Newbie Poster

Re: JSP connection to database

 
0
  #3
Oct 31st, 2008
Hi!..
can anyone help me.. This is urgent..
M doing a project in JSP.. m using Tomcat 4.1..
I want to connect oracle 10g xe as back end..
I have never done that before with anyother database application..
can anyone tel me step by step procedure for that..
Do i have to install any drivers for that..
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: JSP connection to database

 
-1
  #4
Oct 31st, 2008
  1. You should know that urgency on your side will not speed up process on our side, we have right to live too...
  2. Any reason for Tomcat 4 when there s Tomcat 6? If not, either use latest Tomcat 5 or go for Tomcat 6 as is working fine. (http://tomcat.apache.org/)
  3. Oracle website holds numerous examples, like these and you can have look also on How-To examples.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: amrita.r is an unknown quantity at this point 
Solved Threads: 0
amrita.r amrita.r is offline Offline
Newbie Poster

Re: JSP connection to database

 
0
  #5
Nov 7th, 2008
can anyone help me here..

M doing a project in JSP.. M using oracle 10g.. m able to retrieve data from the oracle table.. but m not able to insert.. This code is not showing any error but it is not getting inserted.. do we have to install any drivers..?


  1. <%@ page language ="java" %>
  2. <%@ page import="java.sql.*" %>
  3. <%@ page import="java.io.*" %>
  4. <%@ page import="java.util.*" %>
  5.  
  6.  
  7.  
  8. <html>
  9. <head>
  10. <title>sample</title>
  11. </head>
  12.  
  13. <form method="post">
  14.  
  15. UserName:
  16. <input type="text" fname="t1" >
  17. <br>
  18. <input type="text" lname="t2" >
  19. <br>
  20. <input type="submit" name="sub">
  21.  
  22. <%
  23. String fname=request.getParameter("t1");
  24. String lname=request.getParameter("t2");
  25. %>
  26.  
  27. <%
  28. try{
  29.  
  30. Class.forName("sun.jdbc.odbc.JdbcOdbc");
  31. Connection con=DriverManager.getConnection("jdbc:odbc:MyDatabase","system","database");
  32.  
  33. PreparedStatement st;
  34. st = con.prepareStatement("Insert into ch values (1,2)");
  35. st.setString(1,fname);
  36. st.setString(2,lname);
  37. st.executeUpdate();
  38.  
  39.  
  40.  
  41. %>
  42. <%
  43. }
  44.  
  45.  
  46. catch(Exception e1)
  47. {
  48. out.println("cannot display the records");
  49. }
  50. %>
  51. </form>
  52. </body>
  53. </html>
Last edited by peter_budo; Nov 10th, 2008 at 4:47 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: JSP connection to database

 
1
  #6
Nov 8th, 2008
First thing Amrita is DO NOT CONNECT DIRECTLY TO A DATABASE FROM A JSP.
It is a bad practice to do so. It looks like you are still just studying JSPs, so from the start itself learn how to correctly design you web applications by separating the processing logic and the User Interface. Check this thread by Peter for a good tutorial on how you should go about development is JSPs.
And one more thing please use code tags while posting code, look here for more information.

Note:-
A quick fix exists but I simply will not give it to you cause, you would then just implement the quick fix and skip the rest of the advice.
Last edited by stephen84s; Nov 8th, 2008 at 2:54 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: amrita.r is an unknown quantity at this point 
Solved Threads: 0
amrita.r amrita.r is offline Offline
Newbie Poster

Re: JSP connection to database

 
0
  #7
Nov 9th, 2008
Thank you very much..
that link was really helpful..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: amrita.r is an unknown quantity at this point 
Solved Threads: 0
amrita.r amrita.r is offline Offline
Newbie Poster

Re: JSP connection to database

 
0
  #8
Nov 9th, 2008
can anyone tell me how to make appear strings to appear in text box when i click a button.. i have multiple buttons on my form..
m doing a project in JSP..
i have tried using textarea but it is showing error.. is there any other alternative.?
with short examples will be more helpfull..
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: JSP connection to database

 
0
  #9
Nov 9th, 2008
Originally Posted by amrita.r View Post
can anyone tell me how to make appear strings to appear in text box when i click a button.. i have multiple buttons on my form..
m doing a project in JSP..
i have tried using textarea but it is showing error.. is there any other alternative.?
with short examples will be more helpfull..

That query would belong to the Javascript forum (*I guess*), But you have to show us the relevant piece of code, So that we can point out where you are going wrong.
If you still would like to get some code samples I suggest you look at the Code Snippets section of Daniweb to see if you can find something useful or else google is your friend.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 9
Reputation: amrita.r is an unknown quantity at this point 
Solved Threads: 0
amrita.r amrita.r is offline Offline
Newbie Poster

Re: JSP connection to database

 
0
  #10
Nov 10th, 2008
i want some help here..

i want to display records in text boxes when i click a button..
for eample: there are 3 text boxes..
cid,cname,cadd.. when i type the cid in first field other information ie, cname and cadd should also appear automatically from
databse.. i have multiple submit buttons on my page..

i tried the following method..
[code]
  1. <input type="textbox" id="tb1" name="tb1" value="<%= rs.fields("column") %>" />

but it is creating one more text box even if i give the same textbox name..
m new to JSP.. please do help..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC