Feeds:
Posts
Comments

Archive for April, 2010

Use md5 in pl/sql…

Hi everyone; You can use dbms_obfuscation_toolkit for your Cryptography works. We show you, how can you use md5. And finally we return the results with casting to raw

create or replace
function encodemd5(v_str varchar2) return varchar2 is
 v_string varchar2(100);
 begin
 dbms_obfuscation_toolkit.md5(input_string => v_str,
 checksum_string => v_string);
 return(utl_raw.cast_to_raw(v_string));
end;
/

And finally we can see result with this;

select encodemd5('engin') from dual

That shows us encoded md5 string as result;

B238BAD91D48802AFBDA6A1E315EC5C7

Advertisements

Read Full Post »

Hello Everyone;

Now we are going to fill the JTable with sql query in java. We have to use swing for use of JTable, because Jtable, JScrollPane and JFrame use the Swing library. We use JFrame for create a window, JScrollPane for scroll the data and JTable for list data. We’ll fill JTable with AbstractTableModel and create two class. The 1st. class shows data in the window and the 2nd. class creates table model for fills the JTable. I selected oracle’s all_tables view for listed data. You can see the codes at below;

import java.sql.*;
import java.util.*;
import javax.swing.table.*;

public class FillTable extends AbstractTableModel{

 /**
 *
 */
 private static final long serialVersionUID = -912060609250881296L;
 private ResultSet rs;
 private int rowCount;
 private int columnCount;
 private ArrayList data=new ArrayList();

 public FillTable(ResultSet _rs) throws Exception
 {
 setRS(_rs);
 }

 public void setRS(ResultSet _rs)
 throws Exception
 {
 this.rs=_rs;
 ResultSetMetaData metaData=_rs.getMetaData();
 rowCount=0;
 columnCount=metaData.getColumnCount();
 while(_rs.next()){
 Object[] row=new Object[columnCount];
 for(int j=0;j<columnCount;j++){
 row[j]=_rs.getObject(j+1);
 }
 data.add(row);
 rowCount++;
 }
 }

 public int getColumnCount(){
 return columnCount;
 }

 public int getRowCount(){
 return rowCount;
 }

 public Object getValueAt(int rowIndex, int columnIndex){
 Object[] row=(Object[]) data.get(rowIndex);
 return row[columnIndex];
 }

 public String getColumnName(int columnIndex){
 try{
 ResultSetMetaData metaData=rs.getMetaData();
 return metaData.getColumnName(columnIndex+1);
 }catch(Exception e){
 e.printStackTrace();
 return null;
 }
 }
}

This class creates table model for fills JTable. Before we fill the JTable,  we have to fill the AbstractTableModel, so we talk about MVC in here. (Model View Controller) Let’s see how to  use this class.

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class MyTable {
 public static void main(String[] argv) throws Exception {
 JTable table = new JTable(myModel());

 JFrame f = new JFrame();
 f.setSize(300, 300);
 f.add(new JScrollPane(table));
 WindowListener wClose = new WindowAdapter() {
 public void windowClosing(WindowEvent e){
 System.exit(0);
 }
 };
 f.setVisible(true);

 }

 public static FillTable myModel() throws Exception{
 try {
 Class.forName ("oracle.jdbc.driver.OracleDriver");
 } catch (ClassNotFoundException e) {
 e.printStackTrace();
 }

 Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@Host:port:sid", "user", "pass");

 Statement st = con.createStatement();
 ResultSet rs = st.executeQuery("select owner,table_name,tablespace_name from all_tables");
 FillTable model = new FillTable(rs);
 return model;
 }
}

In this class we are getting a results from sql query and we are creating an object with this results. And then we are creating JTable with this object. The another usage is setModel method.You can use this method as “table.setModel(myModel());”. When you are running the program, you are going to see the data in Jtable.

Read Full Post »