MS SQL连接 [英] MS SQL CONNECTION

查看:95
本文介绍了MS SQL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用"net.sourceforge.jtds.jdbc.Driver"连接SQL Server2000.但是返回以下错误.

java.sql.SQLException: Network error IOException: Connection refused: connect

我已启用TCP/IP并将其设置为端口1433.我也已禁用了防火墙,但问题仍然存在.我正在使用Netbeans ID,为此我还提供了库和jar文件(驱动程序).

任何机构都可以帮助我吗?

Hello Guys,
I am using "net.sourceforge.jtds.jdbc.Driver" for connecting sql server 2000. But returns following error.

java.sql.SQLException: Network error IOException: Connection refused: connect

I have enabled TCP/IP and set at port 1433. I also have disabled my firewall but problem is still there. I am using Netbeans ID and for it i also have included libraries and jar file(driver).

Can any body help me please?

推荐答案

为什么不使用 Microsoft SQL Server JDBC驱动程序 [ ^ ]-它是4型驱动程序.

这是一个小例子:
Why not use Microsoft SQL Server JDBC Driver[^] - it''s a type 4 driver.

Here is a small example:
package ajaworks.msql.connectiontest;
import java.*;
public class test extends Object
{
	private java.sql.Connection  con = null;
    private final String url = "jdbc:microsoft:sqlserver://";
    private final String serverName= "localhost";
    private final String portNumber = "1433";
    private final String databaseName= "AjaWorks.InfoPoint.Data";
    private final String userName = "Local";
    private final String password = "Local";
    
    
    // Informs the driver to use server a side-cursor, 
    // which permits more than one active statement 
    // on a connection.
    private final String selectMethod = "cursor"; 
    
    
    private String getConnectionUrl(){
         return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
    }
    
    private java.sql.Connection getConnection(){
         try{
        	 con = java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost:1433;integratedSecurity=true"); 
        	 
        	 
              if(con!=null) System.out.println("Connection Successful!");
         }catch(Exception e){
              e.printStackTrace();
              System.out.println("Error Trace in getConnection() : " + e.getMessage());
        }
         return con;
     }
    /*
         Display the driver properties, database details 
    */ 
    public void displayDbProperties(){
         java.sql.DatabaseMetaData dm = null;
         java.sql.ResultSet rs = null;
         try{
              con= this.getConnection();
              if(con!=null){
                   dm = con.getMetaData();
                   System.out.println("Driver Information");
                   System.out.println("\tDriver Name: "+ dm.getDriverName());
                   System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
                   System.out.println("\nDatabase Information ");
                   System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
                   System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
                   System.out.println("Avalilable Catalogs ");
                   rs = dm.getCatalogs();
                   while(rs.next()){
                        System.out.println("\tcatalog: "+ rs.getString(1));
                   } 
                   rs.close();
                   rs = null;
                   closeConnection();
              }else System.out.println("Error: No active Connection");
         }catch(Exception e){
              e.printStackTrace();
         }
         dm=null;
    }     
    
    private void closeConnection(){
         try{
              if(con!=null)
                   con.close();
              con=null;
         }catch(Exception e){
              e.printStackTrace();
         }
    }
    public static void main(String[] args) throws Exception
      {
    	test myDbTest = new test();
         myDbTest.displayDbProperties();
      }

}



问候
Espen Harlinn



Regards
Espen Harlinn


我用Google搜索了"java sql服务器连接被拒绝",这是第一个链接:

http://www.websina.com/bugzero/errors/sql-server-connection- error.html [^ ]

如果有帮助的话,大约还有77,000个搜索结果可供选择.
I googled "java sql server connection refused", and this was the first link:

http://www.websina.com/bugzero/errors/sql-server-connection-error.html[^]

If that one does help, there are about 77,000 more search results to chose from.


这篇关于MS SQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆