我使用
从数据库中选择了行SELECT TOP 7 TID FROM historyinsert ORDER BY TID ASC
现在我必须将这7个值存储在字符串中。但我很困惑如何实现。
答案 0 :(得分:0)
你可以在这样的arraylist中列出结果
res = conect.prepareStatement("SELECT something FROM historyinsert ORDER BY TID ASC").executeQuery();
ArrayList<String> list= new ArrayList<String>();
while (res.next()) {
list.add(res.getString("something"));
}
String[] result = new String[list.size()];
result = list.toArray(result);
for(int i =0; i<result.length; i++){
System.out.println(result[i]);
}
答案 1 :(得分:0)
SQL代码:
DECLARE @numbers varchar(MAX)
SET @numbers = ''
SELECT TOP 2 @numbers = @numbers + CAST(Id as nvarchar) + '-' FROM dbo.Person
SELECT @numbers;
结果是:“1-2 - ”
删除“ - ”更改最后一个选择语句,如下所示:
SELECT SUBSTRING(@numbers, 0, len(@numbers));
结果是:“1-2”