简体   繁体   English

使用Android和Firebird JDBC创建连接

[英]Creating connection with Android and Firebird JDBC

I'm having a problem in create an android connection with Firebird database, the app is crashing whenever executes the line of connection. 我在与Firebird数据库创建android连接时遇到问题,只要执行连接线,应用程序就会崩溃。

Code: 码:

cod = ""+edit[0].getText();
cod = String.format("%14s", cod).replace(' ', '0');
String query = "SELECT DS_PRO FROM PROD WHERE CD_PRO = '"+cod+"'";
try{
    Class.forName("org.firebirdsql.jdbc.FBDriver").newInstance();
    System.err.println("jdbc created");
}catch(Exception e){
    System.err.println("Cannot create connection");
}

try{
    Properties props = new Properties();
    props.setProperty("user", "POINTER");
    props.setProperty("password", "pwdb");
    props.setProperty("encoding", "WIN1252");
    try{
        System.err.println("creating connection");
        java.sql.Connection connection = DriverManager.getConnection("jdbc:firebirdsql:192.168.0.196/3050:C:/Fenix/FENIX.FDB",props);
        System.err.println("created connection");
    }
    catch(Exception e){
        System.err.println("error in connection to server");
        System.err.println(e.getMessage());
    }
}
catch(Exception e){
    System.err.println("error in connection to server");
    System.err.println(e.getMessage());
}

This is the message in logcat of eclipse: 这是Eclipse的logcat中的消息:

01-29 09:22:44.774: W/System.err(28820): jdbc created
01-29 09:22:44.774: W/System.err(28820): creating connection
01-29 09:22:44.974: E/AndroidRuntime(28820): FATAL EXCEPTION: AsyncTask #3
01-29 09:22:44.974: E/AndroidRuntime(28820): Process: com.example.testeconnection, PID: 28820
01-29 09:22:44.974: E/AndroidRuntime(28820): java.lang.RuntimeException: An error occured while executing doInBackground()
01-29 09:22:44.974: E/AndroidRuntime(28820):    at android.os.AsyncTask$3.done(AsyncTask.java:300)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.lang.Thread.run(Thread.java:811)
01-29 09:22:44.974: E/AndroidRuntime(28820): Caused by: java.lang.ExceptionInInitializerError
01-29 09:22:44.974: E/AndroidRuntime(28820):    at org.firebirdsql.jdbc.FBDriverPropertyManager.<clinit>(FBDriverPropertyManager.java:142)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:103)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.sql.DriverManager.getConnection(DriverManager.java:179)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at com.example.testeconnection.BdConnect.doInBackground(BdConnect.java:55)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at com.example.testeconnection.BdConnect.doInBackground(BdConnect.java:1)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-29 09:22:44.974: E/AndroidRuntime(28820):    ... 4 more
01-29 09:22:44.974: E/AndroidRuntime(28820): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Set java.util.Properties.entrySet()' on a null object reference
01-29 09:22:44.974: E/AndroidRuntime(28820):    at org.firebirdsql.jdbc.FBConnectionHelper.loadDpbParameterTypes(FBConnectionHelper.java:289)
01-29 09:22:44.974: E/AndroidRuntime(28820):    at org.firebirdsql.jdbc.FBConnectionHelper.<clinit>(FBConnectionHelper.java:106)
01-29 09:22:44.974: E/AndroidRuntime(28820):    ... 11 more

somebody have any information of this error? 有人对此错误有任何信息吗?

The problem is with the properties files in the assets folder, as suggested by Mark. 正如Mark所建议的,问题出在资产文件夹中的属性文件上。 In the initializer 在初始化器中

props = loadProperties("assets/isc_dpb_types.properties");

returns null, which causes the NullReferenceException some lines below. 返回null,这将导致NullReferenceException下面的某些行。 In Android Studio version 2.2 the solution is to add 在Android Studio 2.2版中,解决方案是添加
assets.srcDirs = ['assets'] here: asset.srcDirs = [“资产”]此处:

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
 ....
}
buildTypes {
    release {
       ...
    }
}
sourceSets {
    main {
        assets.srcDirs = ['assets']
    }
}

} }

in the project graddle file. 在项目毕业文件中。 And then the project structure looks like this: 然后,项目结构如下所示: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM