Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DSN-Less JDBC connections

Posted on 2002-03-12
8
Medium Priority
?
320 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 800 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

609 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