943,865 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 72104
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 29th, 2005
0

JSP connection to database

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nelly_1005 is offline Offline
11 posts
since Feb 2005
May 1st, 2005
0

Re: JSP connection to database

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
Reputation Points: 11
Solved Threads: 0
Newbie Poster
adityabakle is offline Offline
8 posts
since Aug 2004
Oct 31st, 2008
0

Re: JSP connection to database

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..
Reputation Points: 8
Solved Threads: 0
Newbie Poster
amrita.r is offline Offline
9 posts
since Aug 2008
Oct 31st, 2008
-1

Re: JSP connection to database

  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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Nov 7th, 2008
0

Re: JSP connection to database

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..?


jsp Syntax (Toggle Plain Text)
  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.
Reputation Points: 8
Solved Threads: 0
Newbie Poster
amrita.r is offline Offline
9 posts
since Aug 2008
Nov 8th, 2008
1

Re: JSP connection to database

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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Nov 9th, 2008
0

Re: JSP connection to database

Thank you very much..
that link was really helpful..
Reputation Points: 8
Solved Threads: 0
Newbie Poster
amrita.r is offline Offline
9 posts
since Aug 2008
Nov 9th, 2008
0

Re: JSP connection to database

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..
Reputation Points: 8
Solved Threads: 0
Newbie Poster
amrita.r is offline Offline
9 posts
since Aug 2008
Nov 9th, 2008
0

Re: JSP connection to database

Click to Expand / Collapse  Quote originally posted by amrita.r ...
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.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Nov 10th, 2008
0

Re: JSP connection to database

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]
jsp Syntax (Toggle Plain Text)
  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..
Reputation Points: 8
Solved Threads: 0
Newbie Poster
amrita.r is offline Offline
9 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in JSP Forum Timeline: How to coalesce multi table
Next Thread in JSP Forum Timeline: Anyway to create a generated HTML file in JSP?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC