Solved

How do i connect my java program to ms sql server

Posted on 2007-11-22
2
14,553 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.

744 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

10 Experts available now in Live!

Get 1:1 Help Now