By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

retriving data on jsp page from sql databse

P: 1
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:

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

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

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

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

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

<% String str;


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;

String s=rs.getString(1);


catch(Exception ex)

Jul 22 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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