on 06-17-2008 3:09 PM
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!!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try using
"select max(columnname) from TST_PRT where ???? "
Regards
krishna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.