类在android中找不到异常

时间:2023-04-21
本文介绍了类在android中找不到异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 android 中为 SQLConnection 使用以下代码:

I am using following code for SQLConnection in android:

public void queryResultSet(String CommandSQL) throws ClassNotFoundException, java.sql.SQLException
    {

        ResultSet rs;
        Connection conn = null;

            Toast msg1 = Toast.makeText(getBaseContext(),
                    "Name = " + CommandSQL, Toast.LENGTH_LONG);
            msg1.show();

             Class.forName("net.sourceforge.jtds.jdbc.Driver");
             String username="14Graficali\Administrator";
             String ConnUrl="jdbc:jtds:sqlserver://14GRAFICALI\MSSQLSERVER2008;DatabaseName=DVDKiosk;user=14Graficali\Administrator;Instance=SQLExpress";
             conn = DriverManager.getConnection(ConnUrl);

            Statement st=conn.createStatement();
            rs=st.executeQuery(CommandSQL);
            while(rs.next())
            {

                Toast msg2 = Toast.makeText(getBaseContext(),
                        "Name = " + rs.getString("UserName"), Toast.LENGTH_LONG);
                msg2.show();
            }

    }

我已经包含了 net.sourceforge.jtds.jdbc.Driver,如下所示:

I have included net.sourceforge.jtds.jdbc.Driver as we can see below :

堆栈跟踪:

08-20 10:57:42.087: W/System.err(400): java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
08-20 10:57:42.087: W/System.err(400):  at java.lang.Class.classForName(Native Method)
08-20 10:57:42.087: W/System.err(400):  at java.lang.Class.forName(Class.java:234)
08-20 10:57:42.087: W/System.err(400):  at java.lang.Class.forName(Class.java:181)
08-20 10:57:42.087: W/System.err(400):  at com.example.registrationapp.Login.queryResultSet(Login.java:93)
08-20 10:57:42.087: W/System.err(400):  at com.example.registrationapp.Login$1.onClick(Login.java:126)
08-20 10:57:42.087: W/System.err(400):  at android.view.View.performClick(View.java:2485)
08-20 10:57:42.087: W/System.err(400):  at android.view.View$PerformClick.run(View.java:9080)
08-20 10:57:42.087: W/System.err(400):  at android.os.Handler.handleCallback(Handler.java:587)
08-20 10:57:42.087: W/System.err(400):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-20 10:57:42.098: W/System.err(400):  at android.os.Looper.loop(Looper.java:123)
08-20 10:57:42.098: W/System.err(400):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-20 10:57:42.098: W/System.err(400):  at java.lang.reflect.Method.invokeNative(Native Method)
08-20 10:57:42.098: W/System.err(400):  at java.lang.reflect.Method.invoke(Method.java:507)
08-20 10:57:42.098: W/System.err(400):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-20 10:57:42.098: W/System.err(400):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-20 10:57:42.098: W/System.err(400):  at dalvik.system.NativeStart.main(Native Method)
08-20 10:57:42.098: W/System.err(400): Caused by: java.lang.NoClassDefFoundError: net.sourceforge.jtds.jdbc.Driver
08-20 10:57:42.107: W/System.err(400):  ... 16 more
08-20 10:57:42.107: W/System.err(400): Caused by: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver in loader dalvik.system.PathClassLoader[/data/app/com.example.registrationapp-1.apk]
08-20 10:57:42.107: W/System.err(400):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-20 10:57:42.107: W/System.err(400):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-20 10:57:42.107: W/System.err(400):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)

请帮帮我.

推荐答案

如果你已经添加了jtds-1.2.5驱动就好了.否则:

If you have already added the jtds-1.2.5 driver, good. Otherwise:

右键单击项目 > 属性 > 库选项卡通过单击添加外部 JAR"添加 jtds-1.2.5.jar 文件

Right click on the Project > Properties > Libraries Tab Add the jtds-1.2.5.jar file by clicking on "Add External JARs"

接下来,在 Order and Export 选项卡(Java Build Path 窗口中的 Libraries 旁边)选中 jtds-1.2.5.jar(以及您可能拥有的任何其他外部 jar)的复选框.

Next, in the Order and Export tab (Right next to Libraries in the Java Build Path window) check the box for jtds-1.2.5.jar (and any other external jars you might have).

这将使用 .apk 文件导出包含驱动程序的 .jar.

This will export the .jar containing the driver with the .apk file.

这篇关于类在android中找不到异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:运行时无命令输出:'am start -n 下一篇:在可以输入所有数据之前,Secondary Activity 进入 Main Activity

相关文章