问题描述:

I'm trying to get my Android connected to my as400 server. Unfortunately when I click on My Connexion button, the driver isn't loaded and I don't know why.

Here my is code:

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");

}

}

}

Here is my xmd code:

<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" />

And here is my error log:

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

Also I've tried many things but I always came to an error. Help me please I want this to work :(

And no I didn't forget to import my jt400.jar which is the "com.ibm.as400.access.AS400JDBCDriver"

Thank you in advance,

Aurelian

网友答案:

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.

相关阅读:
Top