【问题标题】:How to enter array elements into Mysql table? Java如何将数组元素输入Mysql表?爪哇
【发布时间】:2014-04-10 01:36:17
【问题描述】:

我正在使用 split() 函数来填充数组,并且我正在尝试将每个元素输入到 Mysql 表中。做这个的最好方式是什么?如何使循环迭代直到它到达数组的末尾?我在想我可能需要一个从数组中读取的扫描仪对象,这将允许我使用 .hasNext() 函数。还有比这更好的方法吗?

String text = "This is my example text string";
String array[] = text.split(" ");

谢谢

【问题讨论】:

    标签: java mysql arrays


    【解决方案1】:

    首先,text.split(" ") 返回 String[] 而不是 String,但您可以像这样循环遍历数组:

    String text = "This is my example text string";
    String[] array = text.split(" ");
    for (String item : array) {
      // do something with each item 
      // like build an SQL statement
    }
    

    【讨论】:

    • 我的错误,我忘了在我的示例数组声明中添加方括号!但是非常感谢。这正是我所需要的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-17
    • 2013-01-18
    相关资源
    最近更新 更多