Solved

DSN-Less JDBC connections

Posted on 2002-03-12
8
296 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
Comment Utility
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
Comment Utility
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
Comment Utility
I only tried Oracle thin connection...so far
0
 
LVL 1

Expert Comment

by:skinsella
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:cvcarson
Comment Utility
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
Comment Utility
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
Comment Utility
I will try it.
0
 
LVL 1

Expert Comment

by:gigsvoo
Comment Utility
If you face a problem, try this:

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json example 39 110
mapBully challenge 6 88
Java asynchronous logging 4 32
Eclipse IDE - Cannot copy/paste from console output 8 58
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now