📄 insert.jsp
字号:
<%-- Document : insert Created on : 2009-4-19, 13:15:42 Author : Administrator--%><%@page contentType="text/html" pageEncoding="GBK"%><%@page import="java.io.*"%><%@page import="java.sql.*,javax.sql.*,javax.naming.*"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%Connection conn=null;java.lang.String strConn;request.setCharacterEncoding("GBK");PreparedStatement preparedStmt=null;//语句对象java.sql.Statement sqlStmt=null;//语句对象ResultSet sqlRst=null;//结果集对象FileInputStream fis=null;try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); conn=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/","root","root"); String filelocation=request.getParameter("file"); File files=new File(filelocation); fis=new FileInputStream(files); sqlStmt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); String sqlQuery="create database if not exists student;"; int n=sqlStmt.executeUpdate(sqlQuery); String sqlQuery1="USE student;"; //String sqlQuery2="" // +"DROP TABLE IF EXISTS ff;"; String sqlQuery3="CREATE TABLE if not exists ff (name char(10),data longblob);"; int m=sqlStmt.executeUpdate(sqlQuery1); //m=sqlStmt.executeUpdate(sqlQuery2); m=sqlStmt.executeUpdate(sqlQuery3); System.out.println("创建表ff成功!"); preparedStmt=conn.prepareStatement("insert into ff(name,data) values(?,?)"); preparedStmt.setString(1, request.getParameter("name")); preparedStmt.setBinaryStream(2,fis,(int)files.length()); preparedStmt.executeUpdate(); //out.println("操作成功!");}catch(java.sql.SQLException e){ e.printStackTrace();}finally{ if(fis!=null) fis.close(); if(preparedStmt!=null) preparedStmt.close(); if(conn!=null) conn.close(); }%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>数据成功导入到数据库</title> </head> <body bgcolor="black" text="red"> <hr align="center" width="600" size="1" color="#0000FF"> <center><h1><marquee direction="left" behavior="alternate">您的图片已经成功导入到数据库!</marquee></h1></center> <hr align="center" width="600" size="1" color="#0000FF"> <table align="center" border="1" width="80%" bordercolorlight="#0000FF" cellpadding="2" bordercolordark="FFFFFF" cellspacing="0"> <tr> <td align="center"> <a href="input.jsp">继续向数据库录数据</a> </td> <td align="center"> <a href="midpage.jsp">查看已录入的数据</a> </td> </tr> </table> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -