cancel
Showing results for 
Search instead for 
Did you mean: 

access to java DB tables from WDJava

Former Member
0 Kudos

Hi experts!!

I am trying to get the last line of a java table (max key) from my WD,

using a data source alias.

So far the code i've written is this:

DataSource ds = (DataSource) ctx.lookup("jdbc/INSERT_POOL");

Connection con = ds.getConnection();

String SelectStmt = "select * from TST_PRT where ???? " ;

.

I don't know exactly what is the correct statement to get the last line..

The last line will have the maximum value of the key, which is integer.

Please help!!!

Thanx in advance!!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try this code



InitialContext context = new InitialContext();
DataSource data_source = (javax.sql.DataSource)context.lookup( "jdbc/SAPJ2EDB");
Connection connection = data_source.getConnection();	
Statement state = connection.createStatement();
ResultSet resultset = state.executeQuery( "select max(cl_name) from table");

try
{
resultset.next();
   int maxVal = resultset.getInt( 1);
}catch( Exception e)
{}

You can see the context lookup parameter value from visual admin -> JDBC connection.

Regards

Vinod V

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Iria,

If you need the query for selecting the Maximum value in your table then it should be as suggested by other experts in this thread.

The value can be obtained from the ResultSet.

But, the only problem is the column name to be used to retrive this value.

You can do this by two ways:

1. Using resultset.getInteger(<COLUMN_INDEX>); which is 1 here. OR

2. Provide the column name in the query and use it:

i.e. SELECT MAX(NAME_OF_KEY_COLUMN) MAX_NUM FROM TABLE_NAME

resultset.getInteger("MAX_NUM");

Hope it helps.

Regards,

Alka.

Former Member
0 Kudos

try using

"select max(columnname) from TST_PRT where ???? "

Regards

krishna