[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

jdbc connection to ms sql test script

Posted on 2006-04-19
2
Medium Priority
?
223 Views
Last Modified: 2012-05-05
I need a program that will test a JDBC connection from a server running Unix on top of Windows Server 2003.

The main goal is try to figure out why I can make a connection, but when I try to run a query I get a 'connection failure' error.

The test program can be very simple.

Let me know if you need more info.

thanks...Crissy
0
Comment
Question by:faclogistics
2 Comments
 
LVL 4

Accepted Solution

by:
csachdeva earned 2000 total points
ID: 16495411
Example below connect to SQL server 2000 with Microsoft SQL Server 2000 driver for JDBC.

import java.sql.*;

public class getConnection
{
        public static void main(String[] args)
        {
                DB db = new DB();
                Connection conn=db.dbConnect(
          "jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=");
        }

}

class DB
{
        public DB() {}

        public Connection dbConnect(String db_connect_string)
        {
                try
                {
                        Class.forName(
                          "com.microsoft.jdbc.sqlserver.SQLServerDriver");
                         
                        Connection conn =
                          DriverManager.getConnection(db_connect_string);
                         
                        System.out.println("connected");
                        return conn;
                       
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                        return null;
                }
        }
};  

Hope that the code mentioned above will sort out your query.

regards,
Chetan Sachdeva
0
 

Author Comment

by:faclogistics
ID: 16524544
This is great!
Thank you!!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

834 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