跟随教学视频安装好mysql,jdbc,navicat,apache Tomocat,为tomocat配好环境变量,在idea中完成配置工件,连入数据库驱动等
可以通过idea去查看数据库,也可以借助navicat,
以下是代码部分,两个web下的jsp文件,一个负责HTML的页面实现,另一个负责数据库的内容添加以及判断。
<%@ page import="java.sql.*" %> <%@ page contentType="textml; charset=UTF-8" pageEncoding="UTF-8" %> <% request.setCharacterEncoding("UTF-8"); String hey = "请重新录入"; String classname = request.getParameter("course_name"); String teacher = request.getParameter("instructor"); String place = request.getParameter("classroom"); System.out.println(place); try { Class.forName("com.mysql.cj.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/data?useSSL=false&characterEncoding=UTF-8"; String name = "root"; String password = "822611"; Connection conn = DriverManager.getConnection(url, name, password); Statement st; String sqlsearch = "select count(*) from class where classname= '" + classname + "'"; PreparedStatement ps = conn.prepareStatement(sqlsearch); st = conn.createStatement(); ResultSet re = st.executeQuery(sqlsearch); re.next(); int count = re.getInt(1); hey = "保存成功"; String sql = "insert into class(classname,teacher,place) values(?,?,?)";//数据库操作语句(插入) PreparedStatement pst = conn.prepareStatement(sql);//用来执行SQL语句查询,对sql语句进行预编译处理 pst.setString(1, classname); pst.setString(2, teacher); pst.setString(3, place); pst.executeUpdate();//解释在下 System.out.print("数据库连接成功"); conn.close(); request.setAttribute("hey", hey); } catch (Exception e) { System.out.println("数据库连接失败"); System.out.println("错误信息:" + e); } %> <html> <body style="background: blanchedalmond"> <div style="text-align: center" class="container text-center"> <h2 class="form-signin-heading" style="color: brown"> <font size=10> <strong> ${hey} </strong> </font> </h2> <form action="index.jsp"> <input type="submit" value="返回" style="color: darkblue;font-size:35px;background:khaki;border-radius: 15px" > </form> </div> </body> </html>
<meta charset="UTF-8"> <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <?php include('connect.php'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>测试登录页面</title> <style> body{ width: 100%; background-repeat:no-repeat; background-size:100% ; } .login{ float:right; margin-right:20vh; margin-top:15vh; opacity:0.7; height: 35vh; width:50vh; background:#CCFF80; border-radius: 20px; } .title{ font-size:30px; text-align:center; } .biao{ margin-top:20px; font-size:20px; text-align:center; } </style> </head> <body> <div> <div class='login'> <div class='title'>欢迎登录</div> <div class='biao'> <form action="putin.jsp" method='post'> 课程名称:<input type="text" name='course_name'><br><br> 任课教师:<input type="text" name='instructor'><br><br> 上课地点:<select name="classroom"> <option value="一教">一教</option> <option value="二教">二教</option> <option value="三教">三教</option> <option value="基教">基教</option> </select><br><br> <input type="hidden" name="charset" value="UTF-8"> <input type="submit" value='添加' style='width:240px;height:30px;margin-top:25px;background:#B7FF4A'> </form> </div> </div> </div> </body> </html>
标签:10.9,数据库,导入,jsp,background,20px,margin,size From: https://www.cnblogs.com/luoqingci/p/17763486.html