展开全部
<%@ page contentType="text/html;charset=gb2312" import="java.sql.*"%>
<html>
<head>
<title></title>
</head>
<body>
<form method="post">
ID:
<select name="id" onchange="submit()">
<option></option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
</form>
<%!String name="";%>
<%
try{
String id=request.getParameter("id");
if(id!=null)
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost:3307/test";
String user="root";
String password="";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from users where id="+id;
ResultSet rs=stmt.executeQuery(sql);
rs.next();
name=rs.getString("name");
rs.close();
stmt.close();
conn.close();
}
%>
名字:
<input type="text" value=<%=name%>>
<%
}
catch(ClassNotFoundException e)
{
out.println("驱动程序类异常!<br>");
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println("数据库连接或SQL查询异常!<br>");
out.println(e.getMessage());
}
catch(Exception e)
{
out.println("其他异常!<br>");
out.println(e.getMessage());
}
%>
</body>
</html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post">
ID:
<select name="id" onchange="submit()">
<option></option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
</form>
<%!String name="";%>
<%
try{
String id=request.getParameter("id");
if(id!=null)
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost:3307/test";
String user="root";
String password="";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from users where id="+id;
ResultSet rs=stmt.executeQuery(sql);
rs.next();
name=rs.getString("name");
rs.close();
stmt.close();
conn.close();
}
%>
名字:
<input type="text" value=<%=name%>>
<%
}
catch(ClassNotFoundException e)
{
out.println("驱动程序类异常!<br>");
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println("数据库连接或SQL查询异常!<br>");
out.println(e.getMessage());
}
catch(Exception e)
{
out.println("其他异常!<br>");
out.println(e.getMessage());
}
%>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |