数据库|mysql教程
数据库-mysql教程
package servlet;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
android 小程序源码,vscode终端控制台在哪,ubuntu备份流程,外网访问 tomcat配置,巧克力爬虫进口,im php 系统,马尾区企业seo哪家好,php 著名网站lzw
public class Insert extends HttpServlet {
/**
* Constructor of the object.
*/
public Insert() {
super();
}
pcshare 源码编译,vm ubuntu17,tomcat二进制,佛山爬虫展,如何参加php培训,免费seo优化诊断seo顾问lzw
/**
* Destruction of the servlet.
点赞程序源码,vscode搜索源码,ubuntu uos,改变tomcat主页,sqlite 最大多少,编辑网页 插件,购物车java前端框架,python爬虫并做成网页,php 信息提示信息,鸡西seo优化收费,企业内部考试开源网站,微信 网页抽奖,163k模板lzw
*/
public void destroy() {
super.destroy(); // Just puts “destroy” string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“”);
out.println(“”);
out.println(”
out.println(” “);
out.print(” This is “);
out.print(this.getClass());
out.println(“, using the GET method”);
out.println(” “);
out.println(“”);
out.flush();
out.close();
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
boolean flag;
try {
try {
Class.forName(“com.mysql.jdbc.Driver”);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println(“驱动包加载失败。”);
System.exit(0);
}
// 建立与数据库的连接
Connection con=DriverManager.getConnection(“jdbc:mysql:/localhost/org.lyy”
,”root”,”123456″);
// 发送语句
Statement stmt = con.createStatement();
request.setCharacterEncoding(“UTF-8”);
String SID = request.getParameter(“SID”);
String SName = request.getParameter(“SName”);
String SSex = request.getParameter(“SSex”);
String SNum = request.getParameter(“SNum”);
String SPhone = request.getParameter(“SPhone”);
String SSubject = request.getParameter(“SSubject”);
String SCollege = request.getParameter(“SCollege”);
String PlaceOfBirth = request.getParameter(“PlaceOfBirth”);
String SPhoto = request.getParameter(“SPhoto”);
String sql = “select * from Student where SID=” + SID + “‘”;
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
flag = false;
} else {
sql = “INSERT INTO Student(SID,SName,SSex,SNum ,SPhone,SSubject,SCollege,PlaceOfBirth,SPhoto) “
+ “VALUES (‘”
+ SID
+ “‘,”
+ SName
+ “‘,”
+ SSex
+ “‘,”
+ SNum
+ “‘,”
+ SPhone
+ “‘,”
+ SSubject
+ “‘,”
+ SCollege
+ “‘,”
+ PlaceOfBirth
+ “‘,”
+ SPhoto + “‘)”;
// 更新数据库,每一次对数据库进行操作后,都记得更新数据库;
stmt.executeUpdate(sql);
flag = true;
}
response.setContentType(“text/html;charset=UTF-8”); // 定义页面显示类型与编码方式
PrintWriter out = response.getWriter();
out.println(“”);
out.println(“”);
out.println(”
out.println(“”);
out.println(” “);
out.println(“
“);
if (flag == true) {
out.println(“添加成功,可以继续添加… …”);
String trans = “”;
out.println(trans);
} else {
out.println(“添加的用户已经存在,请重新添加… …”);
String trans = “”;
out.println(trans);
}
out.println(“
“);
out.println(” “);
out.println(“”);
out.flush();
out.close();
// 记住要close掉创建的对象和顺序
stmt.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Initialization of the servlet.
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
网上貌似没有正确的