Jdbc连接数据库实验报告(1)

发布时间:2020-07-24 15:16:15 作者:寂岚峰
来源:网络 阅读:3286

一 实验目的

1熟悉myeclipse的使用。

2掌握MySQL的使用。

3掌握jdbc连接数据库。

二实验内容

1在MySQL下创建一个数据库students,并创建表student_info。并且输入记录。

2将mysql的jdbc的jar包导入myeclipse。

3编写注册用户界面的代码login.jsp和insert_stu_1.jsp和登录账号(用数据库中的记录)的代码tijiao.jsp和find.jsp。

三 实验工具

Myeclipse,mySql,和mysql-connector-java-5.0.4-bin.jar。mySql可以用可视化数据库管理工具,也可以用Dos界面下进行操作。Jdbc连接数据库实验报告(1)

可视化数据库管理工具Navicat

Jdbc连接数据库实验报告(1)

Jdbc连接数据库实验报告(1)

Jdbc连接数据库实验报告(1)

Dos下mysql建立数据库和表的操作

信息注册界面

login.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>

  <head>

<title> 注册界面</title>


  </head>

  

  <body>欢迎来到注册界面,请填写你的信息!<hr width="100%" size="3"/>

   <form action="insert_stu_1.jsp" method="post">


<table border="0" width="238" height"252">

<tr><td>用户名</td><td><input type ="text" name="id"/></td></tr>

<tr><td>密    码</td><td><input type ="text" name="passwd"/></td></tr>

<tr align="center">

<td colspan="2">

<input type="submit" value="提     交">&nbsp;&nbsp;&nbsp;

<input type="reset" value="取      消">

</td></tr>

</table>

      </form>

  </body>

</html>

insert_stu_1.jsp:

<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>

<html>

<head><title>插入一条记录</title></head>

<body>

<%String driverName="com.mysql.jdbc.Driver";

String userName="root";

String userPwd="aaa312";

String dbName="students";

String url1="jdbc:mysql://localhost:3306/"+dbName;

String url2="?user="+userName+"&password="+userPwd;

String url3="&useUnicode=true&charsetEncoding=UTF-8";

String url=url1+url2+url3;

Class.forName(driverName);

Connection conn=DriverManager.getConnection(url);

String sql="Insert into students_info(id,passwd) values(?,?)";

PreparedStatement pstmt=conn.prepareStatement(sql);

request.setCharacterEncoding("UTF-8");

String id=request.getParameter("id");

String passwd=request.getParameter("passwd");

pstmt.setString(1,id);

pstmt.setString(2,passwd);

int n=pstmt.executeUpdate();

if(n==1){%>你的信息注册成功,欢迎登录!<br><%}else{ %>注册失败,请重试!<br><%} 

if (pstmt!=null){pstmt.close();}

if(conn!=null){conn.close();}%>

</body></html>

Jdbc连接数据库实验报告(1)

Jdbc连接数据库实验报告(1)



推荐阅读:
  1. Jdbc连接数据库实验报告(2)
  2. JDBC 技术详解1

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

javaweb jdb j

上一篇:查看postgresql系统表的方法

下一篇:服务端启动EXE

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》