<%@ page contentType="text/html;charset=gb2312" import="java.sql.*"%>
<%!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();
}
%>
名字:
>
<%
}
catch(ClassNotFoundException e)
{
out.println("驱动程序类异常!
");
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println("数据库连接或SQL查询异常!
");
out.println(e.getMessage());
}
catch(Exception e)
{
out.println("其他异常!
");
out.println(e.getMessage());
}
%>