我在我的 android 应用程序中遇到问题。这是我的一段代码。谁能给我一个解决方案。我知道这种类型的连接不安全,但我只在我的手机上使用这个应用程序。
public class testConnection
{
public void doConnect()
{
DB db = new DB();
db.dbConnect("jdbc:jtds:sqlserver://192.168.1.3/Test","sa","@135m45@");
}
}
class DB
{
public DB() {}
public void dbConnect(String db_connect_string, String db_userid, String db_password)
{
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println("connected");
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
错误如下:
java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
at info.elshan.sqlserver.SqlServer$DB.dbConnect(SqlServer.java:118)
at info.elshan.sqlserver.SqlServer$testConnection.doConnect(SqlServer.java:106)
at info.elshan.sqlserver.SqlServer$RetreiveFeedTask.doInBackground(SqlServer.java:48)
at info.elshan.sqlserver.SqlServer$RetreiveFeedTask.doInBackground(SqlServer.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: net/sourceforge/jtds/jdbc/Driver
13 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "net.sourceforge.jtds.jdbc.Driver" on path: /data/app/info.elshan.sqlserver-1.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
我还添加了如下库。