开发者

how to read the string from a table which are seperated by commas using mysql

开发者 https://www.devze.com 2023-02-10 07:05 出处:网络
I have a requirement to read the string which is separated by commas and it should be set to JavaBean.the table is like this.

I have a requirement to read the string which is separated by commas and it should be set to JavaBean.the table is like this.

+---------+-----------------------------------开发者_开发知识库--+--------------+
| crsd_id | crsd_crsm_id                        | crsd_lgnm_id |
+---------+-------------------------------------+--------------+
|       3 | 1,2,3,4,5,6,7,8,9,10,11,12,13       | 2,3          |
|       6 | 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 | 3            |
|       7 | 14,15                               | 2,3,4,5      |
+---------+-------------------------------------+--------------+

I have to read the first row (crsd_crsm_id) one by one and it should set to JavaBean like this

courseBean.setCRSD_CRSM_ID(courseListSet.getString(2));

can anyone help me how to do it.


Construct your courseListSet with the crsd_crsm_id field as parameter and then internally split it up via String.split() and offer it for reading

public class CrsdCrsmId {

  private String[] courses;

  public CrsdCrsmId(String in) {
      courses = in.split(",");
  }

  public String getCourse(int i) {
     // TODO check if index i exists
     return courses[i];
  }
...
}

you can then do

String val = mysqldb.getVal();
CrsdCrsmId c = new CrsdCrsmId(val);
String course5 = c.getCourse(5);
0

精彩评论

暂无评论...
验证码 换一张
取 消