0

I'm trying to use a prepared statement to insert a row into SQL Server table. For one of the columns, I want to insert multi line string but couldn't do it.

String persistQuery = "Insert into employee(Name,Address) values (?, ?)";
try (PreparedStatement serStmt = con.prepareStatement(persistQuery, Statement.RETURN_GENERATED_KEYS){
      serStmt.setString(1,name);
      serStmt.setString(2,address);

      serStmt.executeUpdate();
}

This is inserting a row but is making the value of address as single line. I did make sure that address is multiline text by printing it on console before inserting the values.

Sudhik
  • 119
  • 8
  • *"This is inserting a row but is making the value of address as single line."* Why do you say that? – Thom A Jul 20 '20 at 14:43
  • When I query the table for new row, I see that address is all one line. I even copy pasted it from sql server to notepad, I see it as one line. – Sudhik Jul 20 '20 at 15:01
  • 1
    What do you mean you "copy pasted it from sql server"? You can't directly access SQL Server you have to use an IDE. You aren't copying from SSMS and have retain CR/LF off, *are you*? – Thom A Jul 20 '20 at 15:02
  • You are right. If I read that column from IDE, it does have it right. What can I do it to show as multi line in SSMS as well – Sudhik Jul 20 '20 at 16:05
  • 2
    https://stackoverflow.com/a/53115559/2029983 – Thom A Jul 20 '20 at 16:19
  • Do you want to put this as answer and I'll mark it correct ? – Sudhik Jul 20 '20 at 18:26
  • Just upvote my other answer. There's no need to a duplicate answer. – Thom A Jul 20 '20 at 18:53

0 Answers0