当前位置:编程学习 > JSP >>

怎么样配置JSP运行环境

答案:<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
String strName = "";
String strSex = "" ;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/samp_db" ;
String strUser = "root" ;
String strPasswd = "123" ;
Connection conn = DriverManager.getConnection(url,strUser,strPasswd) ;
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE) ;
String strSql = "select * from student" ;
ResultSet rs = stmt.executeQuery(strSql) ;
while(rs.next())
{
strName = rs.getString("name") ;
strSex = rs.getString("易做图") ;
out.print(strName) ;
out.println(strSex) ;
}
stmt.close() ;
conn.close() ;
}
catch(Exception e)
{
e.printStackTrace() ;
}
%>
</body>
</html>



上一个:jsp中通过数据流向客户端传送数据
下一个:JSP/Servlet 中的汉字编码问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,