简体   繁体   中英

connect eclipse web application to sql 2012 database

I'm looking into how to connect a web application to an sql 2012 database "MyTestDatabase" with Windows authentication. I have a similar project that is a simple java application that prints out the contents of a table. here's the code for it...

public class sqldriver {
Connection connection = null;
public sqldriver() {}
public boolean doConnection() {
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        connection = DriverManager
            .getConnection("jdbc:sqlserver://localhost:1433;database=MyTestDB;integratedSecurity=true"); 
        Statement stmt = connection.createStatement();
    } catch (ClassNotFoundException e) {
        System.out.println("ClassNotFoundException : " + e.getMessage()); return false;
    } catch (SQLException e) {
        System.out.println(e.getMessage()); return false;
    }
    return true;
}

All I can find are tutorials for Derby and that's not what I need. The error I keep getting is...

WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path

I've added the sqljdbc_auth.dll to the web-inf/lib, but it doesn't fix the problem. Is there something I've missed?

要加载sqljdbc_auth.dll,您需要将DLL包含在系统PATH上的某个位置,或者需要在Eclipse的运行配置中显式指定java.library.path属性。

make sure you add your database in the odbc !! Go to the start menu and type Odbc then it will appear a dialog >> select the system dsn tap then select add then select your server whatever Mysql Or ms Access after that enter your DB info if you select Mysql then save by click ok then go to your Code and make a string whith your config and send it to the connection object!!

note: You should delete your constructor and leave the compiler run the default..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM