Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do i connect my java program to ms sql server

Posted on 2007-11-22
2
Medium Priority
?
14,579 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 150 total points
ID: 20353200
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

704 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