I want to display data using jsp,javascript and mysql. My Q. is If i select an entry开发者_StackOverflow中文版 suppose 'title' from dropdownlist and give a title name 'partial dif' in textbox and click on search button it should show me all the title names that starts with the letters '....par'. Please help me ...........
suppose u have files named form.jsp, form1.jsp... and a table your_table with columns type and name.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>form.jsp</title>
</head>
<body>
<form action="form1.jsp" method="post" name=frm>
<select name="list">
<option>title</option>
<option>author</option>
<option>publication</option>
</select>
Name<input type="text" name=txt value=""/>
<input type="submit" vaue="GO"/>
</form>
</body>
</html>
form2.jsp
<%String list1=request.getParameter("list");
String name=request.getParameter("txt");
name1=name.substring(0,3);
Connection con;
PreparedStatement ps,ps1,ps2;
ResultSet rs,rs2;
try{
String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:rail";
String username="root";
String password="root";
Class.forName(driverName);
con=DriverManager.getConnection(url,username,password);
ps=con.prepareStatement("Select name from your_table where type=? and name like ?%);
ps.setString(1,list1);
ps.setString(2,name1);
rs=ps.executeQuery();
while(rs.next())
{
out.println(rs.getString(1));
}
}
catch(Exception e)
{out.println(e);}
%>
精彩评论