1

我正在尝试让我的 Android 连接到我的 as400 服务器。不幸的是,当我单击 My Connexion 按钮时,驱动程序没有加载,我不知道为什么。

这是我的代码:

package hello.world;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;


public class HelloworldActivity extends Activity {
    /** Called when the activity is first created. */


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }


    public void Connexion(View view) throws SQLException {
        System.out.println("Tentative de connexion à la base de donnée."); //Connexion 
        String driver = "com.ibm.as400.access.AS400JDBCDriver";

        String url = "jdbc:as400://BEAUFIX;transaction isolation=read uncommitted;date format=iso;naming=system;libraries=*LIBL";   
        Connection conn = null;
        String userName = "GMAOBD60";
        String password = "GMAOBD60";

        try {
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url,userName,password);
          System.out.println("Connected to the database"); 
          conn.close();
          System.out.println("Disconnected from database");
        } catch (Exception e) {
          e.printStackTrace();
          System.out.println("ERROR");

}
}
}

这是我的 xmd 代码:

<Button android:id="@+id/Connexion" android:layout_width="196dp" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_marginTop="100dp" android:text="@string/Connexion" android:layerType="hardware" android:onClick="Connexion" />

这是我的错误日志:

06-05 07:18:56.100: W/System.err(564): java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
06-05 07:18:56.155: W/System.err(564):  at java.lang.Class.classForName(Native Method)
06-05 07:18:56.180: W/System.err(564):  at java.lang.Class.forName(Class.java:217)
06-05 07:18:56.212: W/System.err(564):  at java.lang.Class.forName(Class.java:172)
06-05 07:18:56.241: W/System.err(564):  at hello.world.HelloworldActivity.Connexion(HelloworldActivity.java:33)
06-05 07:18:56.271: W/System.err(564):  at java.lang.reflect.Method.invokeNative(Native Method)
06-05 07:18:56.290: W/System.err(564):  at java.lang.reflect.Method.invoke(Method.java:511)
06-05 07:18:56.321: W/System.err(564):  at android.view.View$1.onClick(View.java:3039)
06-05 07:18:56.340: W/System.err(564):  at android.view.View.performClick(View.java:3511)
06-05 07:18:56.371: W/System.err(564):  at android.view.View$PerformClick.run(View.java:14105)
06-05 07:18:56.371: W/System.err(564):  at android.os.Handler.handleCallback(Handler.java:605)
06-05 07:18:56.380: W/System.err(564):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-05 07:18:56.391: W/System.err(564):  at android.os.Looper.loop(Looper.java:137)
06-05 07:18:56.391: W/System.err(564):  at android.app.ActivityThread.main(ActivityThread.java:4424)
06-05 07:18:56.401: W/System.err(564):  at java.lang.reflect.Method.invokeNative(Native Method)
06-05 07:18:56.410: W/System.err(564):  at java.lang.reflect.Method.invoke(Method.java:511)
06-05 07:18:56.421: W/System.err(564):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-05 07:18:56.431: W/System.err(564):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-05 07:18:56.431: W/System.err(564):  at dalvik.system.NativeStart.main(Native Method)
06-05 07:18:56.441: W/System.err(564): Caused by: java.lang.NoClassDefFoundError: com/ibm/as400/access/AS400JDBCDriver
06-05 07:18:56.460: W/System.err(564):  ... 18 more
06-05 07:18:56.460: W/System.err(564): Caused by: java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
06-05 07:18:56.481: W/System.err(564):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-05 07:18:56.492: W/System.err(564):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-05 07:18:56.492: W/System.err(564):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-05 07:18:56.500: W/System.err(564):  ... 18 more

我也尝试了很多东西,但我总是遇到错误。请帮帮我,我想让这个工作:(

不,我没有忘记导入我的 jt400.jar,即“com.ibm.as400.access.AS400JDBCDriver”

提前谢谢你,奥雷利安

4

1 回答 1

1

I personally haven't tried it but the IBM Toolbox for Java (jt400.jar) may not be compatible with the Dalvik JVM. Dalvik is not a 100% compatible implementation of the Java VM.

Are you sure you want the weight and security implications of a library like the Toolbox distributed on a mobile device? I would recommend a server (AS/400) application to provide services to the mobile clients while managing security, caching, etc.

A framework like Grails that can be deployed natively on the AS/400 makes the server application a breeze. And dealing with XML or JSON services over HTTP will make the mobile application much easier, more robust, and a heck of a lot easier to maintain.

I have a similar application in production supporting over a hundred Windows CE/Mobile clients (Motorola/Symbol handhelds). I'm looking forward to porting the client to Android once the hardware is available.

于 2012-06-05T16:11:14.010 回答