• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Working with date in JDBC

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use java StringTokenizer.

 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please explain what is happening from declaration of the 2d array through till end.
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
This tiny ad is wafer thin:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic