Solved

How do i connect my java program to ms sql server

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

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 62
windows explorer path to command prompt 5 54
fibonacci ten numbers 4 45
servlet example issue 6 46
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

840 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