2015-11-09 56 views
0

我使用Gluon + JDBC進行簡單代碼。 我可以在Android設備上連接此代碼,但不能在Ipad上連接。使用JDBC的膠子示例項目不適用於iOS設備

my build.gradle;

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'org.javafxports:jfxmobile-plugin:1.0.6' 
    } 
} 

apply plugin: 'org.javafxports.jfxmobile' 

repositories { 
    jcenter() 
} 
dependencies { 
    compile 'mysql:mysql-connector-java:5.0.2' 
    iosRuntime 'mysql:mysql-connector-java:5.0.2' 
} 

mainClassName = 'com.mtt8.version15' 

jfxmobile { 
    android { 
     manifest = 'src/android/AndroidManifest.xml' 
     packagingOptions { 
      exclude 'META-INF/INDEX.LIST' 
     } 

     ios { 
      infoPList = file('src/ios/Default-Info.plist') 
      forceLinkClasses = ['com.mtt8.**.*', 'com.mysql.**.*'] 
     } 
    } 
} 

這裏是JavaCode:

private static final String serverIP="192.168.3.188"; 
    private static final String DB_DRIVER = "com.mysql.jdbc.Driver"; 
    private static final String DB_CONNECTION = "jdbc:mysql://192.168.3.188:3306/kasse_sql?useUnicode=true&characterEncoding=UTF-8"; 
    private static final String DB_USER = "root"; 
    private static final String DB_PASSWORD = "MYPASSWORD"; 

    public static Connection connection = null; 
    public static Statement statement = null; 
    public static String SQL = null; 

    public static PreparedStatement pst = null; 


    public static Connection getDBConnection(){ 

     try { 
      Class.forName("com.mysql.jdbc.Driver"); 
     } catch (ClassNotFoundException e) { 
      e.printStackTrace(); 
     } 

     try { 
      //connection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD); 
      connection = DriverManager.getConnection("jdbc:mysql://192.168.3.188:3306/kasse_sql?user=root&password=MYPASSWORD&useUnicode=true&characterEncoding=UTF-8"); 
      msg.setText("Connection is OK"); 
      return connection; 
     } catch (SQLException e) { 
      e.printStackTrace(); 
      msg.setText("Dont Connection"); 
     } 

     return connection; 
    } 

正如我所說的,這個代碼與Android卻沒有關於我的Ipad工作。

我以後./gradlew launchIOSDevice得到以下錯誤

java.sql.SQLException: Unsupported character encoding 'Cp1252' 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910) 
    at com.mysql.jdbc.Buffer.readString(Buffer.java:430) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2823) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812) 
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3269) 
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1182) 
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2644) 
    at com.mysql.jdbc.Connection.<init>(Connection.java:1531) 
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) 
    at java.sql.DriverManager.getConnection(DriverManager.java:179) 
    at java.sql.DriverManager.getConnection(DriverManager.java:144) 
    at com.mtt8.version15.getDBConnection(version15.java:58) 
    at com.mtt8.version15.start(version15.java:32) 
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) 
    at com.sun.javafx.application.LauncherImpl$$Lambda$9.run(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) 
    at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) 
    at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(AccessController.java:52) 
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) 
    at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source) 
    at org.robovm.apple.uikit.UIApplication.main(Native Method) 
    at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:384) 
    at org.javafxports.jfxmobile.ios.BasicLauncher.main(BasicLauncher.java:115) 
IOSWindowSystemInterface : setSwapInterval unimp 
setSwapInterval(1) 
ES2ResourceFactory: Prism - createStockShader: FillPgram_Color.frag 
ES2ResourceFactory: Prism - createStockShader: Texture_Color.frag 
ES2ResourceFactory: Prism - createStockShader: Solid_TextureRGB.frag 
IOSWindowSystemInterface : setSwapInterval unimp 
setSwapInterval(0) 

我有diffently連接字符串嘗試,但結果是一樣的。

任何人都可以說我爲什麼我的代碼不工作在iPad上?

感謝 二崁卡普蘭

+0

檢查'build.gradle'文件,看來你已經包括''內設置android' iOS'。或者是錯誤發佈代碼? –

+0

我的build.gradle就像上面那樣...我只添加了「iosRuntime」這一行 –

+0

該行不是必需的,它會從第一個依賴關係中添加。並檢查:'jfxmobile { 的Android { 清單= 'SRC /安卓/ AndroidManifest.xml中' packagingOptions { 排除 'META-INF/INDEX.LIST' }} IOS { infoPList =文件(「SRC /ios/Default-Info.plist') forceLinkClasses = ['com.mtt8。**。*','com.mysql。**。*'] } }' –

回答

1

似乎有在連接器使用的編碼的改變。

這是對我適用於iOS的最新版本:

dependencies { 
    compile 'mysql:mysql-connector-java:3.1.12' 
} 

對於較新的版本(3.1.13+),我發現同樣的例外,你看:

java.sql.SQLException: Unsupported character encoding 'Cp1252'. 
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java) 

最後,有一個錯字在你的build.gradle文件:

jfxmobile { 
    android { 
     manifest = 'src/android/AndroidManifest.xml' 
     packagingOptions { 
      exclude 'META-INF/INDEX.LIST' 
     } 
     // typo!! iOS should be outside android! 
     ios { 
      infoPList = file('src/ios/Default-Info.plist') 
      forceLinkClasses = ['com.mtt8.**.*', 'com.mysql.**.*'] 
     } 
    } 

}

確保這是您設置的選項:

jfxmobile { 
    android { 
     manifest = 'src/android/AndroidManifest.xml' 
     packagingOptions { 
      exclude 'META-INF/INDEX.LIST' 
     } 
    } 

    ios { 
     forceLinkClasses = [ 'com.gluonhq.**.*', 'com.mysql.**.*'] 
     infoPList = file('src/ios/Default-Info.plist') 
    } 
} 
+0

謝謝你何塞,;。)我糾正我的錯字,並設置我的IOS線在build.gradle ....現在我有一個連接Ipad AIR .. 。但只有版本3.1.12 .....你的東西,它是從robovm側或jdbc側的錯誤? –

+0

我看不出來。這些mysql版本真的很老,並且它們不適用於移動設備。另外,如果您認爲答案是有效的,請將其標記爲已接受,以便其他人可以找到並從中受益。 –

+0

Jose,但版本5.0。2與Android的工作,但不是在Ipad .....在Ipad上工作只有版本3.1.12 .....它似乎是robovm中的錯誤... –

相關問題