0

Configure OracleDataSource in Struts

Following is the configuration to be defined in <data-sources> and </data-sources>

Things to be remember while defining the OracleDataSource in Struts are
  1. URL should be in uppercase otherwise it will throw following exception

    java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL

  2. username and password should be defined in URL string and not separate property. Otherwise it will throw following exception

    java.sql.SQLException: invalid arguments in call

<data-source type="oracle.jdbc.pool.OracleDataSource"
key="ods">
<set-property property="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<set-property property="URL"
value="jdbc:oracle:thin:username/password@localhost:1521:dbname" />
<!--
Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<!--
Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<!--
Maximum time to wait for a dB connection to become available
in ms, in this example 5 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<set-property property="maxWait" value="5000" />
<set-property property="readOnly" value="true" />
<set-property property="autoCommit" value="false" />
</data-source>

|
5

Oracle 10g : How to pass ARRAYS to Oracle using Java?

Here i'm trying to send an array of integers as a parameter to a callablestatement.


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;

import javax.sql.DataSource;

import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.StructDescriptor;

import com.cs.datasource.CardSellerDataSource;

public class TestMessageBroadCasting {

public static void main(String args[]) {

try {
DataSource dataSource = ... ...;

Connection connection = dataSource.getConnection();


String sql = "{call package_name.proc_name(?, ?, ?, ?, ?, ?)}";


Integer [] arr = {1 , 2};
ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
"RESELLERLIST", connection);
ARRAY array = new ARRAY(arrayDescriptor, connection, arr);


CallableStatement callableStatement = (oracle.jdbc.driver.OracleCallableStatement)connection.prepareCall(sql);
callableStatement.setInt(1, 1);
callableStatement.setString(2, "A for apple"
+ System.currentTimeMillis());
callableStatement.setArray(3, array);
callableStatement.setString(4, "0");
callableStatement.setInt(5, 0);
callableStatement.setString(6, "");
callableStatement.registerOutParameter(4, Types.VARCHAR);
callableStatement.registerOutParameter(5, Types.INTEGER);
callableStatement.registerOutParameter(6, Types.VARCHAR);
callableStatement.execute();

String b = callableStatement.getString(6);
System.out.println("message : " + b);

} catch (SQLException e) {
e.printStackTrace();
}

}
}



So, first define an array of integer

Integer [] arr = {1 , 2};

We need a ArrayDescriptor.

ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
"VALUELIST", connection);

VALUELIST is the name of the type defined in your database(Oracle)


Two points we need to note are 
  1. VALUELIST must be defined in SCHEMA LEVEL rather than PACKAGE LEVEL
  2. VALUELIST must always be typed in uppercase letter.
The errors you might get while not defining the name of the type well is
java.sql.SQLException: invalid name pattern: ... ...






|
0

Know the name of currently executing method in Java

This method is used to get the name of method currently executing.

protected String getCurrentlyExecutingMethodName() {
  Throwable t = new Throwable(); 
  StackTraceElement[] elements = t.getStackTrace(); 
  if (elements.length <= 0) return "[No Stack Information Available]";
  // elements[0] is this method
  if (elements.length < 2) return null;
  return elements[1].getMethodName();
}

|
0

Unable to open folder by double clicking...

If double clicking a folder opens search page then try one of the followings

  1. in run type regsvr32 /i shell32.dll
  2. Press Ok 
Or
  1. In registry search for 'MountPoint2' and delete all entries


|

Copyright © 2009 So That I Can Remember All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.