博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MyEclipse------PreparedStatement使用方法
阅读量:4705 次
发布时间:2019-06-10

本文共 1764 字,大约阅读时间需要 5 分钟。

testPreparedStatement.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%    String path = request.getContextPath();    String basePath = request.getScheme() + "://"            + request.getServerName() + ":" + request.getServerPort()            + path + "/";%><%@page import="java.sql.*" %>My JSP 'testPrepareStatement.jsp' starting page    <%        String url="jdbc:mysql://localhost:3306/student?useSSL=true";        String useName="root";        String password="2277092";                Connection conn=null;        Statement stmt=null;                try{            Class.forName("com.mysql.jdbc.Driver");            //out.print("加载驱动类成功");        }        catch(ClassNotFoundException e){            out.print(e);        }                try{        conn=DriverManager.getConnection(url,useName,password);                PreparedStatement pstmtInsert=conn.prepareStatement(            "insert into classinfo(no,name,sex,major,phone,address,age,scoure) values(?,?,?,?,?,?,?,?);");        pstmtInsert.setInt(1, 6);        pstmtInsert.setString(2,"沐白");        pstmtInsert.setString(3, "男");        pstmtInsert.setString(4,"网络工程");        pstmtInsert.setString(5, "2277092");        pstmtInsert.setString(6,"五邑大学");        pstmtInsert.setInt(7, 23);        pstmtInsert.setInt(8,90);                    pstmtInsert.executeUpdate();                pstmtInsert.close();        out.print("插入数据成功");        }        catch(SQLException e){            out.print(e);        }        finally{            try{                if(conn!=null)                    conn.close();            }            catch(Exception e){                out.print("断开数据库连接出现异常");            }        }     %>

 

转载于:https://www.cnblogs.com/tianhengblogs/p/5324512.html

你可能感兴趣的文章
C#中用DateTime的ParseExact方法解析日期时间(excel中使用系统默认的日期格式)
查看>>
W3100SM-S 短信猫代码发送 上
查看>>
Linux IO模式及 select、poll、epoll详解
查看>>
Log4j知识汇总
查看>>
python生成.exe文件
查看>>
PHP面向对象(OOP)----分页类
查看>>
监听SD卡状态
查看>>
vs2017 EFCore 迁移数据库命令
查看>>
serialVersionUID的作用
查看>>
liunx trac 插件使用之GanttCalendarPlugin
查看>>
(14)嵌入式软件开发工程师技能要求总结
查看>>
[hackerrank]Closest Number
查看>>
volatile关键字
查看>>
[Android] TabLayout设置下划线(Indicator)宽度
查看>>
<潭州教育>-Python学习笔记@条件与循环
查看>>
web自动化之验证码识别解决方案
查看>>
netty接收大文件的方法
查看>>
软件工程设计之四则运算
查看>>
SpringMVC @ResponseBody 406
查看>>
Partial Tree UVALive - 7190(完全背包)
查看>>