aspose file tools*
The moose likes JDBC and the fly likes Working with date in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Working with date in JDBC" Watch "Working with date in JDBC" New topic
Author

Working with date in JDBC

kundana sharma
Greenhorn

Joined: Sep 09, 2012
Posts: 10
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

Joined: Jan 08, 2009
Posts: 1478
    
    6

You can probably use oracle's extract function here.

select extract(day from from_date) from tablename


Swastik
Pyla Rao
Ranch Hand

Joined: Jul 10, 2012
Posts: 50
you can use java StringTokenizer.

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

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

Joined: Sep 09, 2012
Posts: 10
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

Joined: Jan 08, 2009
Posts: 1478
    
    6

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

Joined: Sep 09, 2012
Posts: 10
can you please explain what is happening from declaration of the 2d array through till end.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

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

Joined: Oct 21, 2008
Posts: 1107

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working with date in JDBC