I am new in databases and now need a little of your help. I am trying to connect my NetBeans with SQL SERVER using jTDS. MY code is following which I have just copied from a blog. I am getting too many errors
I have already enabled TCP port, SQL SERVER browser,disabled Windows firewall.
/** * ConnectMSSQL.java */ package com.javaworkspace.connectmssql; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ConnectMSSQL { public static void main(String[] args) { try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); Connection connection = DriverManager .getConnection( "jdbc:jtds:sqlserver://localhost:1433;company;selectMethod=cursor", "username", "password"); System.out.println("DATABASE NAME IS:" + connection.getMetaData().getDatabaseProductName()); Statement statement = connection.createStatement(); ResultSet resultSet = statement .executeQuery("SELECT EMPNAME FROM EMPLOYEEDETAILS"); while (resultSet.next()) { System.out.println("EMPLOYEE NAME:" + resultSet.getString("EMPNAME")); } } catch (Exception e) { e.printStackTrace(); } } }
Following is the error:
java.sql.SQLException: Network error IOException: Connection refused: connect at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436) at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184) at java.sql.DriverManager.getConnection(DriverManager.java:579) at java.sql.DriverManager.getConnection(DriverManager.java:221) at com.javaworkspace.connectmssql.ConnectMSSQL.main(ConnectMSSQL.java:19) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) at java.net.Socket.connect(Socket.java:579) at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288) at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251) at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331) ... 4 more BUILD SUCCESSFUL (total time: 2 seconds)
I know I am expecting too much from you but it would be really helpful for me
FOhjk.jpg