<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@page import="java.sql.ResultSet"%><%@page import="java.sql.Statement"%><%@page import="java.sql.Connection"%><%@page import="java.sql.DriverManager"%>Insert title here <%Connection conn=null;String db_url="jdbc:mysql://localhost:3306/shop?serverTimezone=UTC";try { Class.forName("com.mysql.cj.jdbc.Driver"); conn = DriverManager.getConnection(db_url, "root", "123456"); System.out.println("Success connect MySql server!"); } catch (Exception e) { e.printStackTrace();}try { Statement state = conn.createStatement(); System.out.println("添加信息"); String username="dada"; String password="123"; state.execute("insert into admin (username,password) values('" + username + "','" + password+ "')"); state.close();} catch (Exception e) { e.printStackTrace();}conn.close();%>
要到了我想要的结果,连上了数据库,并且添加了数据。