Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java Enumeration Parse results to Database

28 views
Skip to first unread message

Joe S

unread,
May 5, 2012, 3:20:16 PM5/5/12
to
I am working on a project and need some major assistance. Being new
to Java I have gotten a program to enumerate thru an external site and
export to a file the results. My challenge now is that I need to get
the same results with some parsing done and then send it to a database
as a record per line. Any thoughts on how best to do this. Sample
code would be awesome.

markspace

unread,
May 5, 2012, 3:35:12 PM5/5/12
to
No thoughts, really. You need some actual requirements. What is in the
file now, and what do you expect the data to look like once in the
database. Be specific; "with some parsing" is about as unspecific as
humanly possible.




Lew

unread,
May 5, 2012, 11:47:03 PM5/5/12
to
It'd help to have a sample of the code representation of what you mean by "to
enumerate", but I'll take a stab from general principles.

Any errors in interpretation you'll have to correct by being more specific.

Let's say by "to enumerate", you mean something different from what most Java
programmers would assume, "to represent as a Java 'enum'".

I'm guessing you mean something off the wall like, "split into relevant chunks
of meaning (i.e., translate into terminology I care about)".

Otherwise your question makes no sense and you need to do a better job of
asking questions. (The conclusion can be true even if the assumption doesn't
hold.)

So that terminology of interest is what we in the programming biz call a
"model". Let's say you want to model a business customer's operation. Acme
Wine Cooperative scans the Web for good wine deals and assembles them for
perusal. They use terms like "case", "bottle", "varietal", "sauvignon",
"Francis Ford Coppola Winery", etc.

A database these days doesn't have "records". They are based on tables,
comprising rows and columns. The terminology matters.

You should normalize the database at least to third normal form.

But data models are not object models. The data model is a formal slicing of
your raw data into minimal consistent, non-anomalous pieces. That isn't the
same as an object representation of your world.

So let's say you have a type like this:

public interface Wine
{
enum Color { RED, WHITE, BLUSH, ROSE, ; }
Map<Grape, Integer> getVarieties();
Vintner getVintner();
double getRating();
...
}

Obviously no one here can speak to how you cull the data to fill that type,
absent more details from you.

Presumably you'd find keywords in your data sources and extract the values to
fill such objects.

Then pushing that to a database is straightforward if you know JDBC and SQL.
Or are willing to learn it. You can use the JPA (Java Persistence API) library
to handle boilerplate transformation between the object and relational models.
Such libraries are called object-to-relational mapping (ORM) frameworks, and
include EclipseLink and Apache OpenJPA.

You have some studying ahead of you.

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Roedy Green

unread,
May 7, 2012, 10:36:56 PM5/7/12
to
On Sat, 5 May 2012 12:20:16 -0700 (PDT), Joe S <jstec...@gmail.com>
wrote, quoted or indirectly quoted someone who said :
there are a zillion forms the original data may be in. You need to be
much more specific. Once you get in into Java variables, writing it
to SQL is fairly easy. see http://mindprod.com/jgloss/jdbc.html and
http://mindprod.com/jgloss/sql.html

You might read http://mindprod.com/jgloss/screenscraping.html

If you trying to glean data on a website intended for people to read.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Programmers love to create simplified replacements for HTML.
They forget that the simplest language is the one you
already know. They also forget that their simple little
markup language will bit by bit become even more convoluted
and complicated than HTML because of the unplanned way it grows.
.
0 new messages