jspXMl标记语言基础

1.打开命令框进入数据库

打开eclipse创建需要连接的项目

粘贴驱动程序

查看驱动器

使用sql的包

int代表个

conlm代表列名

java 复制代码
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="com.mysql.cj.jdbc.Driver"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>连接mysql</title>
</head>
<body>
	<%
						//主机地址  端口号 数据库,斜杠代表路径
		String url="jdbc:mysql://127.0.0.1:3306/student";
	    String name="root";
		String pw="1125";
		//用什么驱动器使用驱动程序
		Class.forName("com.mysql.cj.jdbc.Driver");
		//获取连接
		Connection con = DriverManager.getConnection(url, name, pw);//使用java.sql然后使用三个
		out.print("数据库连接成功");
		//创建数据库对象,连接成功状态
		Statement sta = con.createStatement();
		//当前状态执行select语句放到结果集合中
		ResultSet rs = sta.executeQuery("select Name from student");
		//打印输出的值,集合的值打印一直打印下一个值,使用
		while(rs.next()){
			out.println(rs.getString("Name"));
		}
		//关闭连接
		rs.close();
		sta.close();
		con.close();

	
	
	
	%>
</body>
</html>

结果对比

相关推荐
放大的EZ4 小时前
user 版本打开adb
adb
nono牛19 小时前
adb devices`ro.boot.serialno` 的实现
adb·智能手机
nono牛19 小时前
MTK平台详解`adb devices`输出的序列号组成
android·linux·adb·智能手机
工具人55552 天前
adb disable-verity
数据库·数据仓库·adb
dessler3 天前
MYSQL-多种方法安装部署
android·mysql·adb
Andy3 天前
Mysql基础1
数据库·mysql·adb
独行soc4 天前
2025年渗透测试面试题总结-224(题目+回答)
网络·python·安全·web安全·adb·渗透测试·安全狮
超人小子5 天前
mysql重置密码
数据库·mysql·adb
rexling15 天前
【MySQL】mysqldump使用方法
数据库·mysql·adb
xhbh6665 天前
【实战总结】MySQL日志文件位置大全:附查找脚本和权限解决方案
android·adb