Solved

DSN-Less JDBC connections

Posted on 2002-03-12
8
303 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
runtime exception 2 41
ejb wildfly example 2 22
login form jsp example 2 37
Bot application - advice 3 38
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

856 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