Thursday, 17 January 2013

Get current row of table in oracle ADF

The following code is use to get the current row.

    DCBindingContainer dcbindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();           
    DCIteratorBinding dcIt = dcbindings.findIteratorBinding("iteratorname");

    RowSetIterator RSIter = dcIt.getRowSetIterator();

    Row r = RSIter.getCurrentRow();

Friday, 11 January 2013

Run mysql script in java

package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.ibatis.common.jdbc.ScriptRunner;

public class SqlScript {
 public static void main(String[] args) throws ClassNotFoundException,
  SQLException {
  String aSQLScriptFilePath = "sql/script.sql";
  // Create MySql Connection
  Connection con = DriverManager.getConnection(
   "jdbc:mysql://localhost:3306/database", "username", "password");
  Statement stmt = null;
  try {
   // Initialize object for ScripRunner
   ScriptRunner sr = new ScriptRunner(con, false, false);
   // Give the input file to Reader
   Reader reader = new BufferedReader(
                               new FileReader(aSQLScriptFilePath));
   // Exctute script
  } catch (Exception e) {
  System.err.println("Failed to Execute" + aSQLScriptFilePath
     + " The error is " + e.getMessage());
  1. sql script should have an semi colen (;) for each end of the statement.
  2. You sql script does not have any select statement.