1. File——》new——》project——》java——》Web Application先创建一个项目

2.创建完成之后找到index.jsp,把代码粘贴上去(注意:这里如果Connection爆红,那就依赖包没有导进去,不要着急,往下看)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>hhhh</title>
</head>
<body>
<table border="1px">
<tr>
<th>姓名</th>
<th>密码</th>
<th>年龄</th>
</tr>
<% Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url="jdbc:mysql://127.0.0.1:3306/student?user=root&password=123456&useUnicode=true&characterEncoding=utf-8";//student为数据库名
//user=root用户 密码password=123456 useUnicode=true&characterEncoding=utf-8是为了防止中文乱码
Connection conn= DriverManager.getConnection(url);
Stateme

本文详细介绍如何在Java Web应用程序中连接和操作数据库,包括创建Web项目、编写JSP页面展示数据库信息、添加Tomcat部署及数据库驱动依赖,以及配置数据库连接等关键步骤。
1515

被折叠的 条评论
为什么被折叠?



