当前位置: 编程技术>移动开发
本页文章导读:
▪Java 调用 Oracle 存储过程回来结果集 Java 调用 Oracle 存储过程返回结果集
转自:http://wxy0327.itpub.net/post/16888/149516
http://www.blogjava.net/TrampEagle/archive/2011/05/03/23605.html
Oracle 存储过程返回结果集用 ref cursor 实现。试验.........
▪ Monitor Package uninstall Event 监听apk程序装配卸载事件 Monitor Package uninstall Event 监听apk程序安装卸载事件
两种方法
1、代码
1, Define a class extends BroadcastReceiver;2, Register broadcast receiver;
UninstallApp receiver = new UninstallApp();
IntentFilter filter = new Inte.........
▪ 当地片选择 本地片选择
package com.yfz;
import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import a.........
[1]Java 调用 Oracle 存储过程回来结果集
来源: 互联网 发布时间: 2014-02-18
Java 调用 Oracle 存储过程返回结果集
推荐:oracle存储过程,http://www./oracle-develop/177537.html
转自:http://wxy0327.itpub.net/post/16888/149516
http://www.blogjava.net/TrampEagle/archive/2011/05/03/23605.html
Oracle 存储过程返回结果集用 ref cursor 实现。试验步骤如下:
1. 建立 ref cursor 类型和过程
drop table prices / drop table test / create or replace package types as type ref_cursor is ref cursor; end; / create table prices( ric varchar(6) primary key, price number(7,2), updated date ) / create or replace function sp_get_prices(v_price in number) return types.ref_cursor as stock_cursor types.ref_cursor; begin open stock_cursor for select ric,price,updated from prices; return stock_cursor; end; / insert into prices select '1',12,sysdate from dual union all select '2',123,sysdate from dual union all select '3',1245,sysdate from dual / commit; --创建表 create table test ( carno varchar2(30), carinfoid number ) / --带 参数,无返回 create or replace procedure pro_ins(mt1 in varchar, mt2 in number) as carinfo_id number; begin insert into test(test.carno,test.carinfoid) values(mt1,mt2); commit; end pro_ins; / --带参数,有返回 create or replace procedure pro_return(para1 in varchar2,para2 out varchar2) as begin select para1||' add ' into para2 from dual; end pro_return; /
2. Java 调用
import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import oracle.jdbc.driver.OracleTypes; public class JDBCDemo { /** * Compile-time flag for deciding which query to use */ private boolean useOracleQuery = true; /** * Class name of Oracle JDBC driver */ private String driver = "oracle.jdbc.driver.OracleDriver"; /** * Initial url fragment */ private String url = "jdbc:oracle:thin:@"; /** * Standard Oracle listener port */ private String port = "1521"; /** * Oracle style of calling a stored procedure */ private String oracleQuery = "begin ? := sp_get_prices(?); end;"; /** * JDBC style of calling a stored procedure */ private String genericQuery = "{ call ? := sp_get_prices(?) }"; /** * Connection to database */ private Connection conn = null; public JDBCDemo(String host, String db, String user, String password) throws ClassNotFoundException, SQLException { // construct the url url = url + host + ":" + port + ":" + db; // load the Oracle driver and establish a connection try { Class.forName(driver); conn = DriverManager.getConnection(url, user, password); } catch (ClassNotFoundException ex) { System.out.println("Failed to find driver class: " + driver); throw ex; } catch (SQLException ex) { System.out.println("Failed to establish a connection to: " + url); throw ex; } } /** * * 返回 Cursor结果集 * * @throws SQLException * @author * @date */ private void exeRetCursor() throws SQLException { String query = useOracleQuery ? oracleQuery : genericQuery; query = "{ call ? := sp_get_prices(?) }"; query = "begin ? := sp_get_prices(?); end;"; System.out.println("Query: " + query + "n"); CallableStatement stmt = conn.prepareCall(query); // register the type of the out param - an Oracle specific type stmt.registerOutParameter(1, OracleTypes.CURSOR); // set the in param stmt.setFloat(2, 1); // execute and retrieve the result set stmt.execute(); ResultSet rs = (ResultSet) stmt.getObject(1); // print the results while (rs.next()) { System.out.println(rs.getString(1) + " | " + rs.getFloat(2) + " |" + rs.getDate(3).toString()); } rs.close(); stmt.close(); } /** * * 无返回结果 * * @throws SQLException * @author * @date */ private void exeNoRet() throws SQLException { String query = "{ call pro_ins(?,?) }"; System.out.println("Query: " + query + "n"); CallableStatement stmt = conn.prepareCall(query); // register the type of the out param - an Oracle specific type // set the in param stmt.setString(1, "abcd"); stmt.setInt(2, 111); // execute and retrieve the result set stmt.execute(); System.out.println(" call pro_ins success"); stmt.close(); } /** * * 返回 String * * @throws SQLException * @author * @date */ private void exeRetSingle() throws SQLException { String query = "{ call pro_return(?,?) }"; System.out.println("Query: " + query + "n"); CallableStatement stmt = conn.prepareCall(query); // register the type of the out param - an Oracle specific type // set the in param stmt.setString(1, "abcd"); stmt.registerOutParameter(2, Types.VARCHAR); // execute and retrieve the result set stmt.execute(); String ret = stmt.getString(2); // print the results System.out.println("get pro_return:" + ret); stmt.close(); } /** * Cleanup the connection */ private void cleanup() throws SQLException { if (conn != null) conn.close(); } /** * Runs the class */ public static void main(String[] args) throws Exception { try { // assign the args to sensible variables for clarity String host = "127.0.0.1"; String db = "orcl"; String user = "zxinweb"; String password = "zxinweb"; // and execute the stored proc JDBCDemo jdbc = new JDBCDemo(host, db, user, password); // 返回 Cursor结果集 jdbc.exeRetCursor(); // 无返回 jdbc.exeNoRet(); // 返回String jdbc.exeRetSingle(); jdbc.cleanup(); } catch (ClassNotFoundException ex) { System.out.println("Demo failed"); } catch (SQLException ex) { System.out.println("Demo failed: " + ex.getMessage()); } } }
推荐:oracle存储过程,http://www./oracle-develop/177537.html
[2] Monitor Package uninstall Event 监听apk程序装配卸载事件
来源: 互联网 发布时间: 2014-02-18
Monitor Package uninstall Event 监听apk程序安装卸载事件
两种方法
1、代码
1, Define a class extends BroadcastReceiver;
2, Register broadcast receiver;
UninstallApp receiver = new UninstallApp(); IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_INSTALL); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addDataScheme("package"); //This line is very important. Otherwise, broadcast can't be received.这一行很得要 registerReceiver(receiver, filter);
2、XML
<data android:scheme="package"></data>
This line is very important. Otherwise, broadcast can't be received. 这一行很重要
<receiver android:name="UninstallApp"> <intent-filter> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package"></data> </intent-filter> </receiver>
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class UninstallApp extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.e("intent", "intent="+intent.getAction()); } }
[3] 当地片选择
来源: 互联网 发布时间: 2014-02-18
本地片选择
package com.yfz; import java.io.FileNotFoundException; import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class Lesson_01_Pic extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.b01); button.setText("选择图片"); button.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { Intent intent = new Intent(); /* 开启Pictures画面Type设定为image */ intent.setType("image/*"); /* 使用Intent.ACTION_GET_CONTENT这个Action */ intent.setAction(Intent.ACTION_GET_CONTENT); /* 取得相片后返回本画面 */ startActivityForResult(intent, 1); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { Uri uri = data.getData(); Log.e("uri", uri.toString()); ContentResolver cr = this.getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); ImageView imageView = (ImageView) findViewById(R.id.iv01); /* 将Bitmap设定到ImageView */ imageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(),e); } } super.onActivityResult(requestCode, resultCode, data); } }
最新技术文章: