努力学习第二天

学习了javaweb里的增

package ceshi;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class aaaaa {
public int zeng(String a,String b) throws Exception {

Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/me","root","921306");

String sql="insert into text value(?,?)";
PreparedStatement stat=con.prepareStatement(sql);
stat.setString(1, a);
stat.setString(2, b);

int temp=stat.executeUpdate();
stat.close();
con.close();

System.out.print(temp);
return temp;
}

 

<%@ page import="ceshi.aaaaa" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String sdengluming=request.getParameter("dengluming");
String smima=request.getParameter("mima");


aaaaa me=new aaaaa();
me.zeng(sdengluming,smima);

 

%>

 

 

</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="first.jsp" method="get">
<table align="center" border="3" width="700">




<tr>
<td>登录名:</td>
<td>
<label>
<input type="text" name="dengluming" maxlength="20"/>
</label>
</td>
</tr>

<tr>
<td>密码:</td>
<td>
<label>
<input type="text" name="mima" maxlength="20"/>
</label>
</td>
</tr>


<tr align="center">
<td colspan="2">
<button>添加<tton>
</td>
</tr>

</table>
</form>

 


</body>
</html>

 

posted @ 2023-02-22 21:49  Weebles  阅读(12)  评论(0编辑  收藏  举报