Solved

DSN-Less JDBC connections

Posted on 2002-03-12
8
306 Views
Last Modified: 2013-11-23
I have 2 SQL Server 2000 Databases. One is the master database of user accounts . In one of the tables in that database is a field that contains a connection string that points to the users database which could be anywhere on any type of database.

How do I create connection objects in Java Using JDBC without using a dsn.
0
Comment
Question by:cvcarson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:onebadboy
ID: 6858707
You need a Type 4 driver ( A Jdbc Driver specifically for the database you are trying to connect to)


click the following link:
http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml
If that doesn't work go to Microsoft's home page and type this in the search box: Microsoft SQL Server 2000 Driver for JDBC

Download and install. It comes with instructions on how to create the connection string. This needs to be on any machine that the applet/application/or servlet will be running on.

Quick Side note. It seems to me that you are going to have to do a little bit of planning because this driver will only work with MS SQL Server not Oracle not MySQL just MS SQL Server. So you're going to need a field in your db table saying what kind of db the connect string is for.


Hope this helps

0
 

Author Comment

by:cvcarson
ID: 6858718
This project was originally for c++ server side code and I was using ADO. But my inexperience with pointers made me migrate to Java (I like much better by the way).

It's no problem adding a field to the db. All of our customers have are on our SQL Server 2000 Db's I was just thinking about the future but for now this will work.

I will test and award points if it works.

Thanks
0
 
LVL 1

Expert Comment

by:gigsvoo
ID: 6859128
I only tried Oracle thin connection...so far
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:skinsella
ID: 6860295
If you don't want to go down the Type 4 route, you could  use the ODBC JDBC Bridge assuming there is a SQL Server ODBC Driver locally (there should be).

Anyway, here's an example for MS-Access, you just need to amend the connection string and driver name for SQL Server.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String db = "jdbc:odbc:Driver={Microsoft Access(*.mdb)};DBQ=C:/foo/foobar.MDB";

Connection DBConn = DriverManager.getConnection(db,"","");

You will have to replace the [Microsoft Access *.mdb] part with the ODBC driver name exactly as it appears in the Driver column of the ODBC DataSource Configuration on your windows machine.

If this is unclear, please repost...

Regards,

Sean
0
 

Author Comment

by:cvcarson
ID: 6860972
I like this idea. But can you give me an example of SQL Server?
0
 
LVL 1

Accepted Solution

by:
skinsella earned 200 total points
ID: 6861049
Just done this and it works (2 differnet ways):

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String connectionString = "jdbc:odbc:Driver={SQL Server};Server=100.99.1.2;Database=MyDatabase;Uid=username;Pwd=password;";

Connection DBConn = DriverManager.getConnection(connectionString);

OR

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String connectionString = "jdbc:odbc:Driver={SQL Server};Server=100.99.1.2;Database=MyDatabase;";

Connection DBConn = DriverManager.getConnection(connectionString, "username", "password");
0
 

Author Comment

by:cvcarson
ID: 6861081
I will try it.
0
 
LVL 1

Expert Comment

by:gigsvoo
ID: 6863146
If you face a problem, try this:

Class myClass = Class.forName(....)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question