jsweety
Technical User
- May 1, 2008
- 2
hi there,
i am inserting data from textarea into a database field
and then displaying the inserted data it is displaying properly but as a continuous string
i want to display it as it was inserted with new line
like if i have inserted through <textarea>
hello
all
there
it is displaying like
hello all there
i want to display as it was
i have three pages as given below and my database field is varchar (using oracle 9i)
1.first.html
2.insert.jsp
3.display.jsp
thanx & regards
sweety
i am inserting data from textarea into a database field
and then displaying the inserted data it is displaying properly but as a continuous string
i want to display it as it was inserted with new line
like if i have inserted through <textarea>
hello
all
there
it is displaying like
hello all there
i want to display as it was
i have three pages as given below and my database field is varchar (using oracle 9i)
1.first.html
Code:
<html>
<body>
<form method="post" action="insert.jsp">
<textarea name="text">
</textarea>
<input type="submit"></input>
</form>
</body>
</html>
2.insert.jsp
Code:
<%@ page import = "java.io.*"%>
<%@ page import="java.sql.*" %>
<%!
String txt;
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:ods","scott","tiger");
txt= request.getParameter("text");
out.println(txt);
PreparedStatement ps = con.prepareStatement("insert into text values('"+txt+"')");
ps.executeUpdate();
out.println("values inserted successfully");
%>
3.display.jsp
Code:
<%@ page import = "java.io.*"%>
<%@ page import="java.sql.*" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:ods","scott","tiger");
PreparedStatement ps = con.prepareStatement("select * from text");
ResultSet rs=ps.executeQuery();
while(rs.next())
{
out.println(rs.getString(1));
}
%>
thanx & regards
sweety