• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to export the data in file using java

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to export the values in 4 column.values for 3 columns are populating properly. I am having trouble with 4th column which is organization column.it is multivalued column.i.e.: it has multiple values.

I have tried to convert from object to String for organization column but didnt help.

Please see the code below:




The output of this code should be:

for ex: Name,UserName,WorkforceID,organization abc,abc,123,xy qwe,q01,234,xy

any help correcting this code will be greatly appreciated.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean it doesn't work? It produces the wrong output? I think you mean "org" to be your fourth column of output, but you haven't included the code that defines "org" or assigns any value to it, so we can't tell you where you're going wrong.
 
Hardik Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the output for the first 3 columns..but not getting the output for the org column..

by the way org column is multivalue column.i.e.:

for the same user name you can have multiple organization assigned to that.
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, are you getting the word "null" in the output or just nothing? You still haven't shown where you assign org a value, but I bet your trouble is starting on line 49 of the listing. There you assign a value to orgList, but then let it immediately go out of scope without your using that value for anything. There should be some relation between org and orgList, right?
 
Hardik Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Greg Charles wrote:OK, are you getting the word "null" in the output or just nothing? You still haven't shown where you assign org a value, but I bet your trouble is starting on line 49 of the listing. There you assign a value to orgList, but then let it immediately go out of scope without your using that value for anything. There should be some relation between org and orgList, right?



I am getting the value "void" for the organization column.You are correct,I havent showed the relation between orgList and org.but when i try to change this to orgList on line 56.I am still getting the output as a "void"

So i have no clue where i am making mistake..or what needs to be changed in this code.
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I can tell you that anything you tried to do with orgList on line 56 would fail at the compiler level, because it is out of scope after line 51. For all intents and purposes, orgList simply doesn't exist at line 56.

So, orgList is a List of what? Strings? Are you trying to turn orgList into a comma-separated String version of what is in orgList? Is org even a String? I might not have been clear before, but you're leaving out details we need in order to help you. In particular, you haven't shown where you define org, or where you assign it any value. You also haven't told us how you want to use orgList.
 
Hardik Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Greg Charles wrote:Well, I can tell you that anything you tried to do with orgList on line 56 would fail at the compiler level, because it is out of scope after line 51. For all intents and purposes, orgList simply doesn't exist at line 56.

So, orgList is a List of what? Strings? Are you trying to turn orgList into a comma-separated String version of what is in orgList? Is org even a String? I might not have been clear before, but you're leaving out details we need in order to help you. In particular, you haven't shown where you define org, or where you assign it any value. You also haven't told us how you want to use orgList.



so,orgList is arraylist.that means..there may be multiple organization value for the same users.
so,output should be like this,

Name,UserName,WorkforceID,organization
thomas,thomas01,123,healthcare
thomas,thomas01,123,finance

In backend database where this data is stored,organization is a String.so, I am trying to convert ArrayList to String.so i can get the values in above format.

the reason i have used the code : List orgList = l.getAttribute("Organization"); not sure if thats correct one.

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

raghvendraa Thomas wrote:In backend database where this data is stored,organization is a String.so, I am trying to convert ArrayList to String.so i can get the values in above format.


Aha! I hadn't bothered to intervene on the good advice you've been getting already, but here I will.

So: this is going into a database? Then why is it also going into a file?
Java is perfectly capable of communicating directly with most databases, so why not just plough your data straight into the table?

Winston
 
Hardik Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so here is what my application is built for:

My application will consume the data from different data sources and will present the hollistic view of identities.

the reason i am exporting this in file since,one of the appowner want their data back along with couple of more attributes from different application.

since my application is the only place where all the app datas are clubbed in together.

 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's where we are now: I know orgList contains a list, which I assume is a list of Strings, but don't know for sure. I've asked you, but you haven't answered. I know you want to convert orgList to org, which I assume is a String, but also don't know for sure. You have tried to make this conversion and it didn't work, but I don't know what didn't work about it, because you haven't told us, nor have you posted the code you tried. In short, you're not giving us what we need to help you.

My best guess is you're trying to do a join. That is, you want to take a list of Strings and convert them into a single String with the values separated by commas. Although the Java Collection API doesn't have a built-in join method, the popular org.apache.commons.lang.StringUtils has a whole raft of them. If you don't want to bring in the commons-lang library, you can at least look up the source code and see how they do it. That's about the best advice I can give you in the absence of more information.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hardik Modi wrote:the reason i am exporting this in file since,one of the appowner want their data back along with couple of more attributes from different application.


Then might I suggest that the "holistic" view of your data is the database?

Pesumably, the appowner that also wants data in serial form (and there's nothing wildly wrong with that; although I suspect it's just laziness on their part) has told you how it's supposed to look - and I suspect it has nothing whatsoever to do with the other 'owners' or 'users' of your system.

My suggestion: Bang it into the database first; and then write a program (or module) to re-extract it in the form that your appowner wants.

Winston
 
Hardik Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct..orgList containts a list.which is list of Strings.
when i tried to populate the organization information using List orgList = l.getAttribute("Organization");

I am getting Void value in my output extract.Ideally i want data to be exported as a lets see..if rthomas is part of 2 organizaton A and B...the data should populated as a ....

Name,UserName,WorkforceID,organization
thomas,rthomas,123,A
thomas,rthomas,123,B
 
Hardik Modi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the above code.to generate the extract file.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Hardik Modi wrote:the reason i am exporting this in file since,one of the appowner want their data back along with couple of more attributes from different application.


You know what? I take back what I said about 'there [being] nothing wildly wrong with that'.

Your appowner is trying to get you to do his work; and its a recipe for trouble.

They sent you the data: Why do they want it back in another format? There are two possibilities that I can see:
1. They want you to validate it according to your database, in which case I would assume some formal agreement about dealing with "invalid submissions".
2. It fulfills some other function that they have in-house, and can blame you for, as a "3rd party", if things go wrong:
"Oh sorry, your honour; we relied on our 3rd party to check everything properly..."

Either way, I'd check with your manager, in writing, to make sure that any misgivings you have are solved before you spend a lot of time on this.

Believe me; I've been the scapegoat when these "gentleman's agreements" go wrong.

Winston
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic