本文介绍了如何使Java与SQL Server一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个基本问题,但我似乎无法找到答案而且我道歉,如果这个问题太愚蠢了,但我们走了:

I know this is a basic question, but I can't seem to find an answer and I apologize, if this question is way too stupid, but here we go:

我应该使用SQL Server(到目前为止没问题)和Java(喜欢java,所以这里也没问题),但现在:我应该做些什么来使组合工作?
我得到了: JRE 1.6 sqljdbc4.jar ...在我将sqljdbc4.jar放入我的类路径之前,我在其中使用了sqljdbc.jar并且测试程序我得到了这个例外:

I am supposed to work with SQL Server (no problem so far) and with Java (love java, so no problem here either), but now: What am I supposed to do to make the combination work?I got: JRE 1.6 and the sqljdbc4.jar ... Before I put sqljdbc4.jar into my classpath I had sqljdbc.jar in it and with a test-program I got this exception:

21.08.2009 09:26:59 com.microsoft.sqlserver.jdbc.SQLServerConnection <init>
SCHWERWIEGEND: Die Java-Laufzeitumgebung (Java Runtime Environment, JRE), Version 1.6,
wird von diesem Treiber nicht unterstützt. Verwenden Sie die Klassenbibliothek
'sqljdbc4.jar', die Unterstützung für JDBC 4.0 bietet.
java.lang.UnsupportedOperationException: Die Java-Laufzeitumgebung (Java Runtime
Environment, JRE), Version 1.6, wird von diesem Treiber nicht unterstützt. Verwenden
Sie die Klassenbibliothek 'sqljdbc4.jar', die Unterstützung für JDBC 4.0 bietet.
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.<init>(SQLServerConnection.java:223)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:840)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at msSqlTest.DB.dbConnect(DB.java:13)
    at msSqlTest.TestConnection.main(TestConnection.java:7)

对不起德国人..它基本上意味着,我应该使用sqljdbc4.jar,b / c驱动程序不支持我正在使用的JRE。所以我把sqljdbc4.jar放到我的类路径中,但它没有用,所以我有点迷茫,我能做什么。

Sorry for the German ... It basically means, that I should use sqljdbc4.jar, b/c the JRE I am using is not supported by the driver. So I put sqljdbc4.jar into my classpath, but it didn't work, so I am kinda lost, what I could do.

也许有人可以告诉我我应该做的是傻瓜式的方式:(

Maybe someone could tell be in an idiot-proof way what I should do :(

哦是的,这是测试appI使用:

Oh yeah, here is the test appI use:

import java.sql.*;

public class TestConnection{
    public static void main(String[] args){
        // Neue DB und los geht's :)
        DB db = new DB();
        db.dbConnect("jdbc:sqlserver://localhost:1433/muff", "user", "pw" );
    }
}

class DB{
    public void dbConnect(  String db_connect_string,
                            String db_userid,
                            String db_password){
        try{
        Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" );
            Connection conn = DriverManager.getConnection(
                            db_connect_string,
                        db_userid,
                        db_password);
            System.out.println( "connected" );
        }
        catch( Exception e ){
            e.printStackTrace();
        }
    }
};


推荐答案

你试过 SQLServer的驱动程序?

Have you tried the jtds driver for SQLServer?

这篇关于如何使Java与SQL Server一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 03:00