Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with data selection when inserted through textarea

Status
Not open for further replies.

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

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
 
before saving text to oracle, try
String strToSave = yourStr.replaceAll(System.getProperty ( "line.separator" ),"<BR>");
or
String strToSave = yourStr.replaceAll("\n","<BR>");

After reading from oracle,
<textarea>
<%
String yourStr2 = textFromDB.replaceAll("<BR>","\n");
out.println(yourStr2);
%>
</textarea>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top