kameshwari
asked on
Error establishing socket on MS SQL JDBC driver
Hi!
I'm a beginner in Java trying to learn JDBC.
I have downloaded and installed the MS SQL JDBC driver type 4. I've followed the tutorial and some code on the net and written the following program:
import java.sql.*;
public class DBWork{
private Connection conn = null;
public static void main(String args[]){
DBWork work = new DBWork();
}
public DBWork(){
try{
Class.forName("com.microso ft.jdbc.sq lserver.SQ LServerDri ver");
conn = DriverManager.getConnectio n("jdbc:mi crosoft:sq lserver:// server123: 1433;Datab ase=Dbxyz; User=sa;Pa ssword=abc ");
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery("select * from ServiceAreas");
while (rs.next()){
System.out.println(rs.getS tring("Are aIdVc"));
System.out.println(rs.getS tring("Nam evc"));
}
}
catch (ClassNotFoundException e1){
System.out.println("ClassN otFoundExc eption: "+e1.getMessage());
}
catch (SQLException e2){
System.out.println("SQLExc eption: " +e2.getMessage());
}
finally{
try{
if (conn != null){
conn.close();
}
}catch (SQLException e3){}
}
}
}
But I get the following error when I run the program. The error occurs on the DriverManager.getConnectio n line:
SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
I've searched the web extensively for a solution. Infact I put the port number '1433' after going through some forums. I have checked the port the SQL server is listening to and it is 1433. The error still persists.
Has anyone got a solution for this problem? I have already spent an entire day on this.
Thanks in advance.
Kameshwari.
I'm a beginner in Java trying to learn JDBC.
I have downloaded and installed the MS SQL JDBC driver type 4. I've followed the tutorial and some code on the net and written the following program:
import java.sql.*;
public class DBWork{
private Connection conn = null;
public static void main(String args[]){
DBWork work = new DBWork();
}
public DBWork(){
try{
Class.forName("com.microso
conn = DriverManager.getConnectio
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery("select * from ServiceAreas");
while (rs.next()){
System.out.println(rs.getS
System.out.println(rs.getS
}
}
catch (ClassNotFoundException e1){
System.out.println("ClassN
}
catch (SQLException e2){
System.out.println("SQLExc
}
finally{
try{
if (conn != null){
conn.close();
}
}catch (SQLException e3){}
}
}
}
But I get the following error when I run the program. The error occurs on the DriverManager.getConnectio
SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
I've searched the web extensively for a solution. Infact I put the port number '1433' after going through some forums. I have checked the port the SQL server is listening to and it is 1433. The error still persists.
Has anyone got a solution for this problem? I have already spent an entire day on this.
Thanks in advance.
Kameshwari.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
ASKER