2012-09-13 20 views
0

我寫的Java插件存儲數據到SQLite數據庫,但是這方面的網址顯示錯誤的PhoneGap本地插件溝通

是否有任何權限是必需的嗎?

package com.tricedesigns; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.Statement; 
import org.apache.cordova.CordovaWebViewClient; 
import org.apache.cordova.api.Plugin; 
import org.apache.cordova.api.PluginResult; 
import org.json.JSONArray; 
import org.json.JSONException; 
import org.sqlite.SQLite; 

import com.sun.java.swing.plaf.windows.resources.windows; 

import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteStatement; 
import android.util.Log; 
import android.view.Window; 



public class HelloPlugin extends Plugin { 

public static final String NATIVE_ACTION_STRING="nativeAction"; 
    public static final String SUCCESS_PARAMETER="laxman"; 
    SQLiteDatabase myDb = null; 
    @Override 
    public PluginResult execute(String action, JSONArray data, String callbackId) { 
     Log.d("HelloPlugin", "Hello, this is a native function called from PhoneGap/Cordova!"); 
//only perform the action if it is the one that should be invoked 
    if (NATIVE_ACTION_STRING.equals(action)) { 
    String resultType = null; 
    try { 
    resultType = data.getString(0); 
    Connection connection = null; 
     ResultSet resultSet = null; 
     Statement statement = null; 

     try { 

      Class.forName("org.sqlite.JDBC"); 
       // webView.loadUrl("jdbc:sqlite:tempdb.db"); 
       connection = DriverManager 
          .getConnection("jdbc:sqlite:tempdb.db"); 



         statement = connection.createStatement(); 
         System.out.println("dddddddddddddddddddddd"); 
         resultSet = statement 
           .executeQuery("SELECT name FROM temp"); 
         while (resultSet.next()) { 
          System.out.println(" NAME:" 
            + resultSet.getString("name")); 
         } 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } finally { 
         try { 
          resultSet.close(); 
          statement.close(); 
          connection.close(); 
         } catch (Exception e) { 
          e.printStackTrace(); 
         } 
        } 

        System.out.println("result typeeeeeeeee"+data.getString(0)); 
       } 
       catch (Exception ex) { 
        Log.d("HelloPlugin", ex.toString()); 
       } 
       if (resultType.equals(SUCCESS_PARAMETER)) { 
        try { 
         return new PluginResult(PluginResult.Status.OK, "Yay, Success,First Plugin for android!!!"+data.getString(0)); 
        } catch (JSONException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
       } 
       else { 
        return new PluginResult(PluginResult.Status.ERROR, "Oops, Error :("); 
       } 
     } 
     return null; 
    } 

} `

我來到這裏錯誤此

09-13 09:53:44.387: W/System.err(330): java.sql.SQLException: opening db: 'tempdb.db': Read-only file system 

回答

0

呼叫從getDatabase在本地方法phonegap.js