我正在尝试使用Eclipse IDE中的sqljdbc4.jar连接到SQL Server 2008。我在运行配置中给出了dll路径,就像在VM参数中一样 - -Djava.libary.path =“C:/ Users / rrpall / workspace / AnnouncmentsFilter / sqljdbc_auth”
我正在从junit测试用例运行我的程序,我发现了以下错误:
我的junit测试用例
package org.nsp.announcmentsfilter.test;
import org.nsp.announcmentsfilter.dao.SqlConnection;
import junit.framework.TestCase;
public class SqlConnectionTest extends TestCase
{
SqlConnection sqlConnection;
public void setUp()
{
sqlConnection = new SqlConnection();
}
public void testConnection()
{
sqlConnection.getSqlConnection();
sqlConnection.setQuery("SELECT NAME FROM NSP_CONTENT_C WHERE FLEXTEMPLATEID = '1293724126089'");
}
}
Java.lang.NoClassDefFoundError: –Djava/libary/path=C: /Users/rrpall/workspace/AnnouncmentsFilter/sqljdbc_auth
Caused by: Java.lang.ClassNotFoundException: –Djava.libary.path=C: .Users.rrpall.workspace.AnnouncmentsFilter.sqljdbc_auth
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
弹出窗口说“ 找不到主类:“Djava.library.path = C:/ Users / rrpall / workspace / AnnouncmentsFilter / sqljdbc_auth。程序将退出”
我的原始代码是
package org.nsp.announcmentsfilter.dao;
import Java.sql.*;
public class SqlConnection
{
String driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String connectionUrl = "jdbc:sqlserver://KWIDBSQLD02:10432;integratedSecurity=true";
String dbUser="root";
String dbPwd= "";
Connection conn = null;
public void getSqlConnection()
{
try
{
Class.forName(driverClassName);
conn = DriverManager.getConnection(connectionUrl);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public ResultSet setQuery(String query)
{
Statement statement;
try
{
statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(query);
return resultSet;
}
catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}
有人可以帮我解决这个问题吗?