Solved

How do i connect my java program to ms sql server

Posted on 2007-11-22
2
14,557 Views
Last Modified: 2008-02-01
I am beginner and I would like to create a connection to ms sql server and I have an Error Message: java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://192.168.1.251:1433/adsEngine


Here is my code:
 

import java.sql.Connection;

import java.sql.DriverManager;
 

public class DBMS {

	

	public DBMS(){

		

	}

    public static String strErrorDtls = "";

    

    /** Get database connection */

    public  Connection getConnection() {

        Connection conn = null;

        try {
 

            String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
 

            String uri = "jdbc:microsoft:sqlserver://192.168.1.251:1433/adsEngine";

           

            Class.forName(driver);
 

            conn = DriverManager.getConnection(uri, "", "");

            System.out.println("connection is up");

        } catch (Exception ex) {

            ex.printStackTrace();

            strErrorDtls += ex.getMessage() + " ";

        }

        return conn;

    }    

    

    public static void main(String args[]){

    	DBMS dbms = new DBMS();

    	dbms.getConnection();
 
 

    }

}

Open in new window

0
Comment
Question by:dharween0629
2 Comments
 
LVL 16

Expert Comment

by:gnoon
ID: 20337779
You need to have database driver (typicaly a .jar file) from database vender (maybe d/l from website), and place it in java classpath (or run setup.exe to automatic set for you) on your matchine before run program.

D/L Microsoft SQL Server 2005 JDBC Driver 1.2 from here http://www.microsoft.com/downloads/details.aspx?familyid=C47053EB-3B64-4794-950D-81E1EC91C1BA&displaylang=en
0
 
LVL 9

Accepted Solution

by:
ysnky earned 50 total points
ID: 20353200
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

919 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

19 Experts available now in Live!

Get 1:1 Help Now