aspose file tools*
The moose likes JDBC and the fly likes Connecting to sql server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting to sql server" Watch "Connecting to sql server" New topic
Author

Connecting to sql server

Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Hi all,

This is my application
/////////////////////////////
import java.sql.*;
import javax.swing.*;


class A{
public void conn(){


try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
JOptionPane.showMessageDialog(null,"Driver Ok");
Connection conn =

DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;user=user;password=pass");
JOptionPane.showMessageDialog(null,"SQL Ok");
Statement stmt=conn.createStatement( );
JOptionPane.showMessageDialog(null,"Connect Ok");
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Error");
System.out.println(e);
}




}
public static void main(String [] args){
A a=new A();
a.conn();
}
}

////////////////////////////////////

after runing

/////////////////////////////
C:\test>javac A.java

C:\test>java A
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establis
hing socket.

C:\test>
/////////////////////////////
Can any one give a an solution to this error

Thank You
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Sameera,
It looks like the program can't connect to the database. Check the port is correct and that you can connect to the database using the command line.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to sql server
 
Similar Threads
Why this OverFlow error during updating?
Connecting to MS SQL Server 2000 Personal Edition
Connection with database Help
connecting to Webtrends reporting DB using JDBC-ODBC
testCode runs GREAT on Local comp, fails on network comp. using mySQL