jsp传值到mysql数据库查询表,并把对应的值传到页面显示出来

2024-11-16 20:38:01
推荐回答(1个)
回答1:

<%@ page import="java.sql.*"消瞎纤 %>
<%
String s;
s=request.getParameter("id");
int id;
id=Integer.parseInt(s);
out.print(id);
Connection conn;
Statement st;
ResultSet rs;
String driver;
String url;
driver="com.mysql.jdbc.Driver";
url="jdbc:mysql://localhost:3306/bookdb";
try{
Class.forName(driver);
conn=DriverManager.getConnection(url,"root","拿仿"神罩);
st=conn.createStatement();
rs=st.executeQuery("select * from t_student where no="+id);
while(rs.next()){
out.print(rs.getString(2));
}
}catch(Exception e){
out.print(e);
}
%>