qZ4MNdVK.zip
(466.94 KB)
mysql连接到tomcat是不是需要一个文件拷贝到lib文件夹中,哪里可以得到?
这个驱动包.
将它放到你的web项目文件夹的lib下
如果你用的是NetBeans的话,那只是在库里添加这个jar就可以了.
[CODE]<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!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>JSP</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/tennis","root","admin");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select playerno from players");
while(rs.next()){
out.println(rs.getString(1));
}
rs.close();
stmt.close();
con.close();
}catch(Exception exc){
out.print(exc.toString());
}
%>
</body>
</html>[/CODE]