aspose file tools*
The moose likes Tomcat and the fly likes Tomcat and jdbc/odbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat and jdbc/odbc" Watch "Tomcat and jdbc/odbc" New topic
Author

Tomcat and jdbc/odbc

dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
hi all

i am having doubt on tomcat using
jdbc odbc bridge driver to connect to
SQl Server database

i am using tomcat 6.0 and jdk 1.6.0_01
i have created a jsp in which i am connecting
to my database as below





i am working on this code for a long time but have no solutions
to it.


everytime i run i am getting

error=java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

is there anything i need to change in Tomcat
so that it can get jdbc/odbc driver........and later connect to
my database.

because there is nothing wrong with my dsn i am sure
as i have checked it when i call the same
code for connection above in a simple java program it works
it connects to database and executes query
but it is not working with tomcat........


any help on the above will be realy great


Thanks in advance..........

Dhwani:>Its always to soon to quit.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're creating your connections right in your classes, Tomcat will have nothing to do with whether it works or not.

As long as Tomcat can see your JDBC driver (in this case the JDBC-ODBC driver)
you should be able to connect with it.

You already have log thread in the servlets forum on this topic and I'd like to avoid seeing another, parallel one here. If this were my problem, I would put Tomcat aside for a minute and try connecting to your database from a plain old Java class. Once you can do that, start working on getting it to work from within your container.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
hi!!

i sincerely apologise for reposting the same
topic what actualy i thought was since my java
code for connection works in a normal java
program why not in Tomcat 6.0

so may be if some
configurations are required in Tomcat 6.0.(Server.xml,web.xml)..since
my Tomcat does not have access to jdbc/odbc driver it shows from
Exception thrown
so furthur how can it connect to my database
thats why i switched here........with a fresh topic

i apologise once again will not at all post on this topic
any furthur


[ January 30, 2008: Message edited by: dhwani mathur ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You don't need to configure anything in your web.xml file if you are creating the connections from your Java class directly.
If you were using Tomcat's container managed connection pooling, then you would.

What errors are you seeing?


PS: Since this is working from a plain old Java class, it looks like you just need to insure that the driver visible to the container.
I'm going to close the thread in servlets to insure that this conversation doesn't get spread out too thin.

-Ben
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
hi

Thanks for the response

First of all,i am not creating my connection
from java class,i am creating my connection from
JSP scriplet <% connection to database code here%>


Since i am a beginner i dont have any idea on
Tomcats container managed connection pool.

and in my server logs i am getting these exceptions


ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by dhwani mathur:
hi

Thanks for the response

First of all,i am not creating my connection
from java class,i am creating my connection from
JSP scriplet <% connection to database code here%>



It's one and the same thing. JSPs are converted into Servlets and whatever code you write in scriptlet, goes into service() method of that servlet.

When you are creating connections "yourself" (like you did) then there is nothing you are doing specific to tomcat or any server.

Did you place your driver (jar) in the lib folder of tomcat or application?
[ January 31, 2008: Message edited by: ankur rathi ]
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by ankur rathi:


Did you place your driver (jar) in the lib folder of tomcat or application?


However, in that case, the exception would be ClassNotFoundException, I guess.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I wrote a very simple tutorial kind of page on JDBC that might help you:


JDBC Notes



Version : 0.1
Documented by : Ankur Rathi


Connection through DSN:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbcSN_Name","username","password");

To create DSN:

programs -> settings -> control panel -> administrative tools -> data sources (ODBC)

create a new DSN here.


Thin Driver:

Take classes11.zip into class path.

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbcracle:thin:@localhost:1526atabase_Name", "system", "manager");

To Know Database Name:
1] open a command prompt and type �net start�
2] open a command prompt and type �services.msc�

This will list down all the services, one of the entry will be like this:

oracleservice_SHREE

Here �_SHREE� is Database Name


OCI8 Driver:

Take classes11.zip into class path.

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbcracleci8:@TNS_Name", "system", "manager");

To Know TNS Name:

Search �tnsnames.ora� file

A TNS Entry look like this:

SUNILDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = SUNIL01) (PORT = 1521))
)
(CONNECT_DATA =
(SID = SUNILDB)
(SERVER=DEDICATED)
)
)


Here TNS Name is �SUNILDB�

dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
hi ankur!!!


i am realy happy to say my problem is solved



i was mistaken by creating user DSN ,i created
System DSN its working absolutely fine with no problems
thanks for all help and such a gud explanation

thanks for all the help
to all Bartenders and Ranchers

i apologise for reposting of same topic

Finally after a long time i got a
solution..........

Dhawni:>Its always too soon to quit.
[ January 31, 2008: Message edited by: dhwani mathur ]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

That's great dhwani :thumb:


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat and jdbc/odbc