简体   繁体   中英

mySQL Java Database Modeling

In trying to create a SQL database that can be queried within java, but I'm not sure how to structure it. Here are my categories: 1. State 2. Cites within each state 3. Venues within each city 4. Specifics about each venue

This might seem simple to some, but I am concerned with the amount of information that will be located in category #4, since that category alone could house the most data. The most important part of this is that I would of course need to query this information in category #4 and return the information. Is it common practice to have a category with a lot of information in it or do I need to break down category #4 even further? Also, another issue I am coming across is that I am using java to create arrays or arrayLists for all this info and I don't know how to get the data from the arrays to mysql. Any info is appreciated.

Get your code to work with the most direct mapping between your domain objects and your tables. If down the line you realize you're storing too much data in one table, you'll be able to refactor by breaking that data more. But I wouldn't worry too much about having too much data in a table, that's what databases are made for. What you need to think about is how you're going to access that data, and make sure you have proper indexes and primary keys on it.

To insert several rows of data from Java to mysql, search the Web. Java: Insert multiple rows into MySQL with PreparedStatement may be a good start.

Creating relational tables for a relational database and querying relational tables in a relational database using Java are two different tasks.

First, let's create the relational tables.

State
-----
State ID
State Name
...

In the State table, you store all the information about a state. The State ID is the primary (clustering) key, and is an auto-incrementing integer.

City
----
City ID
State ID
City Name
...

In the City table, you store all the information about a city. The State ID is a foreign key to the State table. In the few cases where a city is in multiple states, you create a city row for each state. As an example, Bristol, Virginia and Bristol, Tennessee is a city in two states.

Venue
-----
Venue ID
City ID
Venue Name
Venue Type
Venue Address
...

Venue Type
----------
Venue Type ID
Venue Type Description

In the Venue table, you store all the information about a venue. The City ID is a foreign key to the city. You can get the state information from the city row.

In the Venue Type table, you store the various venue types, like hotel, theater, restaurant, retail store, etc.

The only reason you would create a Specifics table is if there are multiple types of specifics for a venue. Otherwise, you can add a Venue Description column to the Venue table.

First, get your relations for your relational tables correct. Then, you can see how to map the relations to Java classes. Classes consisting of lists are probably the correct approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM