zoukankan      html  css  js  c++  java
  • jsp连接Sql2008add操作

    <%@ page language="java" contentType="text/html; charset=gb2312"
     pageEncoding="gb2312" import="java.sql.*"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>update数据</title>
    </head>
    <body>
     <center>

       <%
        String url = "jdbc:sqlserver://localhost:1433; DatabaseName=JavaJdbc";
        String user = "sa";
        String password = "110";
        Connection conn = null;
        PreparedStatement pstmt = null;
        
        String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        try {
         
         Class.forName(driverName).newInstance();
        
         conn = DriverManager.getConnection(url, user, password);
      
        } catch (ClassNotFoundException e) {
         out.println(e);
        } catch (SQLException e) {
         out.println("连接SQLserver数据库失败!!!!!!");
        }
        
        try{
        Statement stmt = conn.createStatement();
        String sql="insert into employee(id,name,age,address,city) values(2,'小名',20,'binghai','binghai road')";
        stmt.executeUpdate(sql);
        }catch(SQLException e){
         out.println("insert失败!");
        }
        try{
         if(pstmt!=null){
          pstmt.close();
          pstmt=null;
         }
         if(conn!=null){
          conn.close();
          conn=null;
         }
        }catch(Exception e){
         out.println("数据库关闭异常!");
        }
        out.println("insert成功!");
       %>
     </center>
    </body>
    </html>

  • 相关阅读:
    每日总结6.14
    每日总结6.13
    每日总结6.12
    每日总结6.11
    用户故事与敏捷方法阅读笔记4
    用户故事与敏捷方法阅读笔记3
    团队冲刺第一阶段燃尽图
    团队冲刺10
    智能物联网:将人工智能的力量带入物联网
    MyEclipse修改文件后Building workspace时间过长
  • 原文地址:https://www.cnblogs.com/atwanli/p/2771664.html
Copyright © 2011-2022 走看看