zoukankan      html  css  js  c++  java
  • 代码实例

    Test.java

    package Ke;
    import  Ke.util;
    import java.sql.*;
    import java.util.Scanner;
    public class Test {
        static Connection conn;
        static PreparedStatement ps = null;
        static ResultSet rs;
        static String sql = "select * from Ke_c";
        static util ut= new util();
        static Scanner in = new Scanner(System.in);
         static String Ke;
         static String Tea;
         static String Di;
         public static String a_Ke() {
             return Ke;
         }
         public static String a_Tea() {
             return Tea;
         }
         public static String a_Di() {
             return Di;
         }
    public static int add(String Ke,String Tea,String Di)
    {
         conn= ut.getConn();
         String sql="insert into Ke_c values(?,?,?)";
         int b=0;
         System.out.println(Ke);
         try {
             ps=conn.prepareStatement(sql);
             ps.setString(1,Ke);
             ps.setString(2, Tea);
             ps.setString(3, Di);
             int a=ps.executeUpdate();
             if(a>0) {
                 b++;
                 System.out.println("添加成功");
                 
             }
             else {
                 System.out.println("添加失败");
             }
         }catch(Exception e) {
             e.printStackTrace();
         }
         try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
        return b;
    }
    public static int uqdate(String Ke,String Tea,String Di) {
        int b=0;
        conn=ut.getConn();
        ps=null;
        sql="update Ke_c set Tea=?,Di=? where Ke=?";
        try {
             ps=conn.prepareStatement(sql);
             ps.setString(1, Tea);
             ps.setString(2, Di);
             ps.setString(3,Ke);
             int a=ps.executeUpdate();
             if(a>0) {
                 b++;
                 System.out.println("修改成功");
                 
             }
             else {
                 System.out.println("修改失败");
             }
        }catch(Exception e) {
            e.printStackTrace();
        }
        try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
        return b;
        
    }
    public static int delete(String Ke) {
        int b=0;
        conn=ut.getConn();
        ps=null;
        sql="delete from Ke_c where Ke=?";
        
        try {
            ps=conn.prepareStatement(sql);
            ps.setString(1, Ke);
            int a=ps.executeUpdate();
             if(a>0) {
                 b++;
                 System.out.println("删除成功");
                 
             }
             else {
                 System.out.println("删除失败");
             }
        }catch(Exception e) {
            e.printStackTrace();
        }
        try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
        return b;
        
    }
    public static void find(String a) {
        conn=ut.getConn();
        ps=null;
        ResultSet rs=null;
        String id;
        sql="select * from Ke_c where Ke=?";
        try {
            ps=conn.prepareStatement(sql);
            ps.setString(1, a);
            rs=ps.executeQuery();
            if(rs.next()) {
                 Ke = rs.getString("Ke");
                 Tea = rs.getString("Tea");
                 Di = rs.getString("Di");
               
            }
        }catch(SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                 if(ps!=null)ps.close();
                 if(conn!=null)conn.close();
             }catch(Exception e2) {
                 e2.printStackTrace();
             }
        }
    }
    public static void main(String[] args) {
        //add();
        //uqdate();
        //System.out.println("请输入要删除课程");
        System.out.println("请输入查找课程:");
        String a;
        Scanner scan=new Scanner(System.in);
        a=scan.next();
        //delete(a);
        find(a);
        
    }
    }

    add.jsp

    <%@page import="Ke.Test"%>
    <%@page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!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=UTF-8">
    <title>增加</title>
    <script type="text/javascript"">
    
        function validate()
    
        {
        var Ke=document.forms[0].Ke.value;
        var Tea=document.forms[0].Tea.value;
        var Di=document.forms[0].Di.value;
        if(Ke.length<=0){
    
            alert("课程不能为空,请输入课程!");
    
            return false;
    
        }
    
        else if(Tea.length<=0){
    
            alert("教师不能为空,请输入教师姓名!");
    
            return false;
    
        }
    
        else if(age<=0){
    
            alert("地点不能为空,请输入地点!");
    
            return false;
    
        }
    
     
    
            else if(Di.length<=0){
    
            alert("专业不能为空,请输入所学专业!");
    
            return false;
    
        }
    
     
    
        else{
    
            return true;
    
        }
    
            //document.getElementById("form").submit();
    
        }
    
        </script>
    </head>
    <body>
     <form action="addresult.jsp" method="post" id="form" onSubmit="return validate()" >
    
     <input type="hidden" name="methodName" value="0"/>
    
    <h4>  课程:<input type="text" name="Ke"title="课程不能为空"></input><br></h4>
    
    <h4>  任课教师:<input type="radio" name="Tea" value="Wangjianmin">王建民
    
                <input type="radio" name="Tea" value="liulijia">刘立嘉
                <input type="radio" name="Tea" value="liudan">刘丹
                <input type="radio" name="Tea" value="wanghui">王辉
                <input type="radio" name="Tea" value="yangziguang">杨子光
                <br></h4>
    <h4>  上课地点:<input type="radio" name="Di" value="yijiao">一教
                <input type="radio" name="Di" value="erjiao">二教
                <input type="radio" name="Di" value="sanjiao">三教
                <input type="radio" name="Di" value="jijiao">基教
                <br></h4>
     <input type="submit" value="完成"/>
       </form>
     
    </body>
    </html>

    addresult.jsp

    <%@page import="Ke.Test"%>
    <%@page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!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=UTF-8">
    <title>添加结果</title>
    </head>
    <body>
    <%
    request.setCharacterEncoding("utf-8");
     if(Test.add(request.getParameter("Ke"),request.getParameter("Tea"),request.getParameter("Di"))==1)
     {
         {
                out.print("<script language = 'javascript'>alert('添加成功');</script>");
                response.setHeader("refresh", "0;url=Zhu.jsp");
                }
     }
     else{
         out.print("<script language = 'javascript'>alert('添加失败');</script>");
         response.setHeader("refresh", "0;url=Zhu.jsp");
            //out.println("添加失败");
     }
     %>
    </body>
    </html>
  • 相关阅读:
    Flash builder发布Air程序时设备配置文件supportedProfiles的配置
    Apple Swift中文入门教程【转发】
    管理书籍
    Android Market google play store帐号注册方法流程 及发布应用注意事项
    BMFont使用图片自定义字体(无需字体文件)
    google广告尺寸
    AndroidMainfest.xml文件解释
    win10 vscode ssh-remote配置免密登录
    vscode java配置
    vscode Java 11 or more recent is required to run. Please download and install a recent JDK”
  • 原文地址:https://www.cnblogs.com/smartisn/p/10090247.html
Copyright © 2011-2022 走看看