473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

retriving data on jsp page from sql databse

Sir,
I want to fetch data from a table in sql server database on a jsp page...i make text to be searched input from user through an html page and on jsp page i am getting that data by getParameter() method and passing that variable in sql like query whose syntax is "select * from tablename where columnname like 'f%'" where f is the text received by getparameter()..

my code is:
//search.html

<body>
<form action="" searchbox.jsp" method="post">
<input type="text" name="searchitem" value=" " size="30" maxlength="30">
<input type="submit" name="search" value="search">
</form>
</body>



//searchbox.jsp
<%@ page import = "java.util.*;" %>

<%@ page import=" java.sql.*;" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>

<%! Connection con;
PreparedStatement pstmt;
Statement stmt;
ResultSet rs;
%>

</head>
<body>
<% String str;
str=request.getParameter("searchitem");

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


con=DriverManager.getConnection("Jdbc:Odbc:ds_name ");

Statement st=con.createStatement();
String st1="'";
String st2="%";
String str2=st1.concat(str);
String str3=str2.concat(st2);
String str4=str3.concat(st1);


rs=st.executeQuery("select * from items where itemname like '" +str4+ "'");
int count=0;
if(rs.next())
{

String s=rs.getString(1);


count++;
out.println(s);
if(count>0)
{
out.println("success");
}
else
{
out.println("fail");
}
}


}
catch(Exception ex)
{
}

%>
</body>
</html>
Jul 22 '12 #1
0 1866

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: iffy agbim | last post by:
I have a form that displays information selected from an Access Data base. A select statement is used to do this on my asp page SQLQuery = "SELECT * FROM tblopgaCOm2 WHERE billNo = '" &...
2
by: Niyazi | last post by:
Hi, I have to retrieve a data from AS400 DB2 and after working with data I have to export into one of existing Excel file. I can connect into specific library in AS400 DB2 using AS400...
2
by: chitrapu | last post by:
hiii everybody, i have a little code that inserts the data into the databse. but the problem is the insertion should be peroformed only when a button is clicked. i have problems in this because i...
1
by: believeinblue44 | last post by:
I have recently spent countless hours building, tweaking, and perfecting numerous forms and they all are working fine now and i'm nearly done...now all i have to do is put them as Web Data Pages, put...
0
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
i have a main page of a website with a lot of data. and i am thinking of not using an access to the DB all time but rather read the data from an XML that will be updated (beacuse the data isn't...
3
by: remdeb648 | last post by:
Hi, I am programming a multi-criteria filter in an Access Data Page. I successed to make a simple criteria filter using the code below: (the code is on a button click action) ...
5
by: JCCDEVEL | last post by:
Hello, We have a small program that allows licensees around the world to submit requests to our home office. They complete the request on an ASP form (with an HTM page) over a https connection. ...
0
by: pchaitanya | last post by:
hi all, suppose in a table if i have columns namely name,entrydate now on retriving and binding to a gridview how can I get names rowwise and entrydate columnwise on a gridview on...
2
by: guddy | last post by:
I have 1 page named one.jsp and i want data from this page to all other pages without submitting that page.... i have tried the session but i is not working.
0
by: Richard Forrest | last post by:
I have created a data access page using MS Access 2003 and am having the following issue: I have a "Save" button on the data page and the page is working correctly but does not provide the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.