• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Working with date in JDBC

 
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.
 
Rancher
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • 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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use java StringTokenizer.

 
Swastik Dey
Rancher
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • 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: 2265
20
Android Java ME Eclipse IDE Java
  • 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: 2265
20
Android Java ME Eclipse IDE Java
  • 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.
 
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)
 
That feels good. Thanks. Here's a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic