如何在MySQL表列的一个字段中存储多个值?

时间:2015-05-09 20:16:50

标签: java mysql sql jdbc

我想为这些列stops的所有站点创建表id, name,route, lat, long, arrivaltime,但我不知道如何管理它以获取停靠表中的路由列?既然一条路线有很多数字?

{
   "id": 1
   "stops_name": "Amersham ",
   "route": "8,4,7,34,45,8017, 57, 20,......... 30 entries"
   "arrival_time": {
                    "mon-fri": [ "05:38", "06:07","06:37",.....50 entries],
                    "sat": ["05:34","06:01","06:31",...........50 entries],
                    "son": ["06:02","06:34","07:04",...........50 entries]
                   },
    "stops_lat": 83.837994,
    "stops_long": 18.700423
 }



stt.execute("CREATE TABLE IF NOT EXISTS stops"
        + "(stop_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
        + " name varchar(30) NOT NULL, "
        + " route INT(11) NOT NULL, "
        + " lat double(10,6) NOT NULL, "
        + " longi double(10,6)NOT NULL) " );

stt.execute("CREATE TABLE IF NOT EXISTS arrivaltimes(id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
        +  " weekday VARCHAR(20) NOT NULL,"
        + "arrivaltime time NOT NULL,"
        + " stop_id INT, FOREIGN KEY fk_stop_id(stop_id) REFERENCES stops(stop_id) )" );

1 个答案:

答案 0 :(得分:0)

据我了解,您希望创建一个关系数据库结构。并且您希望在止损和路线表之间建立关系。

因此假设一个站点可以属于多个路由,并且一个路径可以有多个站点,这些站点之间存在多对多的关系。

例如,你可以看看这里 http://www.tutorialspoint.com/hibernate/hibernate_many_to_many_mapping.htm

如何在Hibernate中实现这种关系。