首先导入包
import android.util.Base64;
String 变量=android.util.Base64.encodeToString(字符串.getBytes(),Base64.DEFAULT);
也可简写为
String 变量=Base64.encodeToString(字符串.getBytes(),Base64.DEFAULT);
至于解码
byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT);
String 变量=new String(b);
byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT);
2014年1月27日 星期一
Export有關android手機的Database
有關android手機的Database (expoortDB.db) 目前可以Export 出來,
方法如下
1 open dos command
2 切換到 android sdk path
ex: d:
cd D:\adt-bundle-windows\sdk
3 輸入 adb shell (確認Phone Device 是連線中狀能)
ex: adb shell
4 輸入 run-as package-name
ex: run-as tw.com.test
(ps 在AndriodManifest.xml 找的到pakcage name)
5 輸入 ls 有看到Databases 目錄
6 輸入 cd databases
7 輸入cat expoortDB.db > /sdcard/expoortDB.db
8 再到手機的APPs-> 我的檔案
找到expoortDB.db 用分享經由 ( Gmail or 雲端硬碟) 把檔案滙出
9 由7~8 把想要的檔案滙出
再用SQLite Database Browser 軟体(free) 即可以看內容的Table 結構及資料
方法如下
1 open dos command
2 切換到 android sdk path
ex: d:
cd D:\adt-bundle-windows\sdk
3 輸入 adb shell (確認Phone Device 是連線中狀能)
ex: adb shell
4 輸入 run-as package-name
ex: run-as tw.com.test
(ps 在AndriodManifest.xml 找的到pakcage name)
5 輸入 ls 有看到Databases 目錄
6 輸入 cd databases
7 輸入cat expoortDB.db > /sdcard/expoortDB.db
8 再到手機的APPs-> 我的檔案
找到expoortDB.db 用分享經由 ( Gmail or 雲端硬碟) 把檔案滙出
9 由7~8 把想要的檔案滙出
再用SQLite Database Browser 軟体(free) 即可以看內容的Table 結構及資料
2014年1月23日 星期四
Developing for Android in Eclipse: R.java not generating
Solution
- Make sure that anything the
R.links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken,Rwill not regenerate. - If you somehow hit something and created
import android.Rin your activity, remove it. - Run Project -> Clean. This will delete and regenerate R and BuildConfig.
- Make sure Project -> Build Automatically is ticked. If not, build it manually via
Menu -> Project -> Build Project. - Wait a few seconds for the errors to disappear.
- If it doesn't work, delete everything inside the /gen/ folder
- If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties.
- Check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken.
- Right-click your project > properties > Android. Look at the Project Build Target and Library sections on the right side of the page. Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the Target Name is Android 4.2. If your Library has an X under the reference, remove and re-add the library until there's a green tick. This might happen if you've moved a few files and folders around.
What to do if R doesn't regenerate
This usually happens when you have a broken xml file.
- Check errors inside your XML files, mainly within the /res/ folder
- Common places are /layout/ and /values/ especially if you've changed one of them recently
- Check
AndroidManifest.xml, I find that often I change a string, and forget to change the string name fromAndroidManifest.xml. - Check that
Android SDK Build-toolsis installed. Window->Android SDK Manager->Tools->Android SDK Build-tools - Make sure when you update the
Android SDK Tools, you also update theAndroid SDK Platform-toolsandAndroid ASK Build-tools. Build fails silently if they don't match. - If you can't find the issue, right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. This doesn't solve the problem, but it will clear out the extra errors to make the problem easier to find.
I know there's already a lot of answers here, but this is the main link on Google, so I'm compiling all the advice here and hope it helps someone else new to this :)
2014年1月22日 星期三
Java: Passing Array To Oracle Stored Procedure
This tutorial guides us on how to pass Array objects from Java to stored procedures in Oracle and also, how to retrieve an array object in Java.
All PLSQL arrays can not be called from java. An array needs to be created as
TYPE, at SCHEMA level in the database and then it can be used with ArrayDescriptor in Java, asoracle.sql.ArrayDescriptor class in Java can not access at package level.Database Code
First, Create an array, at SCHEMA level. An example is shown below:
CREATE TYPE array_table AS TABLE OF VARCHAR2 (50); -- Array of StringCREATE TYPE array_int AS TABLE OF NUMBER; -- Array of integers |
Next, Create a procedure which takes an array as an input parameter and returns an array as its OUT parameter.
An example of one such procedure is shown below, which has 2 parameters -
- an array of String as its IN parameter – p_array
- an array of Integers as OUT parameter – p_arr_int
CREATE OR REPLACE PROCEDURE SchemaName.proc1 (p_array IN array_table, len OUT NUMBER, p_arr_int OUT array_int)AS v_count NUMBER;BEGIN p_arr_int := NEW array_int (); p_arr_int.EXTEND (10); len := p_array.COUNT; v_count := 0; FOR i IN 1 .. p_array.COUNT LOOP DBMS_OUTPUT.put_line (p_array (i)); p_arr_int (i) := v_count; v_count := v_count + 1; END LOOP;END;/ |
After this, Execution permission would be required to execute the procedure created by you:
GRANT EXECUTE ON SchemaNAme.proc1 TO UserName; |
Java Code
Create a java class which makes a call to the procedure
proc1, created before.
Below is an example which contains the whole flow from creating a connection with the database, to making a call to the stored procedure, passing an array to Oracle procedure, retrieving an array from an Oracle procedure and displaying the result.
import java.math.BigDecimal;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.Types;import oracle.jdbc.OracleCallableStatement;import oracle.jdbc.internal.OracleTypes;import oracle.sql.ARRAY;import oracle.sql.ArrayDescriptor; public class TestDatabase { public static void passArray() { try{ Class.forName("oracle.jdbc.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:url ","UserName","Password");; String array[] = {"one", "two", "three","four"}; ArrayDescriptor des = ArrayDescriptor.createDescriptor("SchemaName.ARRAY_TABLE", con); ARRAY array_to_pass = new ARRAY(des,con,array); CallableStatement st = con.prepareCall("call SchemaName.proc1(?,?,?)"); // Passing an array to the procedure - st.setArray(1, array_to_pass); st.registerOutParameter(2, Types.INTEGER); st.registerOutParameter(3,OracleTypes.ARRAY,"SchemaName.ARRAY_INT"); st.execute(); System.out.println("size : "+st.getInt(2)); // Retrieving array from the resultset of the procedure after execution - ARRAY arr = ((OracleCallableStatement)st).getARRAY(3); BigDecimal[] recievedArray = (BigDecimal[])(arr.getArray()); for(int i=0;i<recievedArray.length;i++) System.out.println("element" + i + ":" + recievedArray[i] + "\n"); } catch(Exception e) { System.out.println(e); } } public static void main(String args[]){ passArray(); }} |
訂閱:
文章 (Atom)