gpt4 book ai didi

java - 如何在 SQL Server 中插入换行符

转载 作者:行者123 更新时间:2023-11-30 02:57:43 31 4
gpt4 key购买 nike

我有一个 java 应用程序。

我将一些文本插入sql server数据库

java:

courriel.setTxtCouContenu(corps);

当我检查我的 var corps 时,我有这个:

enter image description here

您可以看到\r\n

所以当我查看数据库时没有换行符。

我的插入语句(iBatis):

<statement id="insert"
parameterClass="test.business.bo.TestBO"
resultClass="java.math.BigDecimal">
INSERT INTO dbo.E_COUR (ID, CORPS,)
VALUES (#testBO.id:Numeric#,
#corps:Varchar#)
SELECT SCOPE_IDENTITY()
AS value
</statement>

最佳答案

当您使用插入的内容时,\r\n 是否仍在字符串中,或​​者会消失吗?

在 SSMS 中尝试一下:

declare @tbl TABLE(testString VARCHAR(100));
insert into @tbl VALUES('test with \r\n encoded line break')
,('test with' + CHAR(13) + CHAR(10) + 'windows line break')
,('test with' + CHAR(10) + 'simple line break');

现在切换到(输出到文本(ctrl+T))

SELECT * FROM @tbl;

结果:

test with \r\n encoded line break

test with
windows line break

test with
simple line break

使用“输出到数据网格(ctrl+D)”,您无论如何都不会看到换行符...

关于java - 如何在 SQL Server 中插入换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36787813/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com