Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working with date in JDBC

 
kundana sharma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a column name from_date as a timestamp in my Oracle Database.
Sample data:
The Question is How can I extract only the day part from the database using JDBC in java code.I mean I just need the '13' part in 13-Dec-12 7:41:54 PM ,'27' part in 27-Dec-12 7:41:54 PM.
I want the data to be in an array in increasing order.
please help I am not well versed in java.
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can probably use oracle's extract function here.

select extract(day from from_date) from tablename
 
Pyla Rao
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use java StringTokenizer.

 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can get the formatted value from the query itself, then what's the need to use StringTokenizer, please correct me if I am wrong.
 
kundana sharma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am stuck here.

I am not able to make out What result set contains.Is it an array of ints?
please help Dey
My task:I want to calculate interest for an account_no at the end of the month.
Sample database:
Code for calculating interest:

I am not able to make out how to extract timestamp into result set and then use it.
please help.
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It didn't allow me to post the code in code tags.
try {
sqlAccNo="select count(*) from month_txn where account_no="+accno;
day="select extract(day from from_date) day,balance from month_txn where account_no="+accno +" order by day";
Statement st2;
ResultSet rs2;
st2=conn.createStatement();
rs2=st2.executeQuery(day);
st=conn.createStatement();
rs=st.executeQuery(sqlAccNo);
double arr[][]=null;
if(rs2.next()){
int rowCount1=rs2.getInt(1);
arr=new double[rowCount1][2];

}
int ctr=0;
while (rs.next()) {
String day=rs.getString(1);
double principle=rs.getDouble(2);
arr[ctr][0]=Double.parseDouble[day];
arr[ctr][1]=principle;
ctr++;

}
//arr should have now day and balance for that day
 
kundana sharma
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please explain what is happening from declaration of the 2d array through till end.
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you find the 2nd array. There is only one array with 2 dimensions. 1st element contains the day and 2nd element contains the balance.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Where do you find the 2nd array. There is only one array with 2 dimensions. 1st element contains the day and 2nd element contains the balance.

he didn't say second he said 2 dimensional (2d)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic