使用jTDS将Netbeans连接到SQL SERVER

时间:2013-11-21 14:18:18

标签: java sql-server netbeans sqlconnection jtds

我是数据库的新手,现在需要一点帮助。我正在尝试使用jTDS将我的NetBeans与SQL SERVER连接起来。我刚刚从博客中复制了我的代码。我收到太多错误

我已经启用了TCP端口,SQL SERVER浏览器,禁用了Windows防火墙。

   /**
 * 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();
        }
    }
}

以下是错误:

enter image description here

我知道我期待你的太多,但对我来说真的很有帮助

0 个答案:

没有答案