使用mysql新建一个数据库
jdbc调用
实现数据查询
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from student");
while(rs.next()){
out.println("姓名:"+rs.getString(1)+"年龄:"+rs.getInt(2)+"专业:"+rs.getString(3)+"<br>");
}
rs.close();
st.close();
conn.close();
%>
</body>
</html>