Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Connecting Net-Beans to SQLSERVER using jTDS

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Connecting Net-Beans to SQLSERVER using jTDS

    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Connecting Net-Beans to SQLSERVER using jTDS

    You have left off the first line(s) of the error message.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Connecting Net-Beans to SQLSERVER using jTDS

    Quote Originally Posted by Norm View Post
    You have left off the first line(s) of the error message.
    now i have updated the error message

Similar Threads

  1. Slot Machine game in Java. using Net Beans.
    By leo24 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 28th, 2012, 10:32 PM
  2. Net Beans - Look and Feel
    By russdb in forum AWT / Java Swing
    Replies: 1
    Last Post: June 26th, 2012, 05:07 PM
  3. Net-beans-java
    By Tanmaysinha in forum Java IDEs
    Replies: 2
    Last Post: November 6th, 2011, 05:45 AM
  4. Net Beans OR Eclipse
    By sanjuds in forum Java IDEs
    Replies: 6
    Last Post: August 16th, 2011, 04:36 AM