wood burning stoves*
The moose likes Java in General and the fly likes can anyone help please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "can anyone help please" Watch "can anyone help please" New topic
Author

can anyone help please

Srinivasan Narasimahan
Greenhorn

Joined: Jul 18, 2012
Posts: 3
sorry sir am new to this forum. still i dont know where to insert code..

I have got no problem with insertion. but while generating seq id as cmd0001..so on, at the end of file say cmd00009, after reading another file, it again starts from cmd00001 and throws error. Please give any solution. Thanks

[EDIT: removed URGENT from the title]
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8398
    
  23

Srinivasan Narasimahan wrote:I want to read data from .csv file...

Srinivasan,

When you post code please UseCodeTags (←click). Just click the Edit button and follow the instructions.
Also, please read the page thoroughly, because the lines you've posted are far too long.

It's for your own good, because nobody is likely to answer your question as posted, let alone "urgently".

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1512
    
    5

Hello Srinivasan Narasimahan,

Welcome to CodeRanch!

Please, UseCodeTags. Its quite difficult to read the code without it - especially when its quite long, contains very long lines, and also contains some commented code.

Also, please remember that PatienceIsAVirtue.

Going even further, please ShowSomeEffort. Have you tried to debug the code? As you've identified the root cause, you can try to check whether you are resetting sequence anywhere.

I would really suggest to go through your code again - not for this particular problem, but the way you are writing it - e.g. too much roles are assigned to single method (connecting to DB, throwing a query, getting result, processing the data and so on), using proper names for class and method etc.

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8398
    
  23

Srinivasan Narasimahan wrote:I have got no problem with insertion. but while generating seq id as cmd0001..so on, at the end of file say cmd00009, after reading another file, it again starts from cmd00001 and throws error.

Well, we'd have to see how you're calling this to make sure, but you're either creating a new 'myclass' object (which should be 'MyClass', BTW), or you're simply running the whole program again with a different file name. If you want to keep sequence numbers between calls, then the easiest thing is to make 'i' static, viz:
static int i = 0;

If you need to keep the value between calls to the program, then you'll have to save the "last sequence number" somewhere.

Winston
Srinivasan Narasimahan
Greenhorn

Joined: Jul 18, 2012
Posts: 3
Thank you sir. But it(SEQ_ID) also should be in a sequence order. like CMD0001,CMD0002.....CMD000n for eg.. after non insertion of a row in DB since req value is not found, the seq_id also changes its state by skipping numbers. so I thought to run seq_id in a different table instead all these mess.

I want help to join the two tables permanently into 3rd table. or by inserting the seq_id into the table consisting of data. or any way using only java. that is while running the select query after insertion of both tables, only a single table should appear containing all data..

Please help thanks..
Srinivasan Narasimahan
Greenhorn

Joined: Jul 18, 2012
Posts: 3
Winston Gutkowski wrote:
Srinivasan Narasimahan wrote:I have got no problem with insertion. but while generating seq id as cmd0001..so on, at the end of file say cmd00009, after reading another file, it again starts from cmd00001 and throws error.

Well, we'd have to see how you're calling this to make sure, but you're either creating a new 'myclass' object (which should be 'MyClass', BTW), or you're simply running the whole program again with a different file name. If you want to keep sequence numbers between calls, then the easiest thing is to make 'i' static, viz:
static int i = 0;

If you need to keep the value between calls to the program, then you'll have to save the "last sequence number" somewhere.

Winston



Thank you sir. But it(SEQ_ID) also should be in a sequence order. like CMD0001,CMD0002.....CMD000n for eg.. after non insertion of a row in DB since req value is not found, the seq_id also changes its state by skipping numbers. so I thought to run seq_id in a different table instead all these mess.

I want help to join the two tables permanently into 3rd table. or by inserting the seq_id into the table consisting of data. or any way using only java. that is while running the select query after insertion of both tables, only a single table should appear containing all data..

Please help thanks..
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8398
    
  23

Srinivasan Narasimahan wrote:Thank you sir. But it(SEQ_ID) also should be in a sequence order. like CMD0001,CMD0002.....CMD000n for eg.. after non insertion of a row in DB since req value is not found, the seq_id also changes its state by skipping numbers. so I thought to run seq_id in a different table instead all these mess.

Several things:
1. "CMD0001" is not a number at all; it's a String.
2. In database terms, it's "derived data" (ie, it's made up of the combination of the String "CMD" and a formatted sequence number).
3. Unless you use other prefixes, the "CMD" is redundant (ie, it just wastes space).
4. The formatting of the sequence number creates an arbitrary and probably undocumented restriction (it cannot be > 9999).
5. You still have the problem I stated above: You cannot maintain a running sequence number between invocations of a Java program unless you save the "last value" outside the program (eg, in a file).
6. Even given the above, if your program could be run by more than one person on the same system, they could still create duplicate sequence numbers.

I want help to join the two tables permanently into 3rd table. or by inserting the seq_id into the table consisting of data. or any way using only java. that is while running the select query after insertion of both tables, only a single table should appear containing all data.

For all the reasons I gave above, a "pure Java" solution for insertion is difficult and probably impractical. My suggestion would be to use an actual database sequence number or define the table as having an auto-incrementing primary key.

The join, on the other hand, is an entirely different matter, and can probably be solved entirely in SQL.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can anyone help please