zoukankan      html  css  js  c++  java
  • jdbc作业3

    删除学生信息

    package com.hanqi.db;
    
    import java.sql.*;
    import java.util.Scanner;
    
    public class JdbcHW3 {
    
        public static void main(String[] args) {
            
             Connection con=null;
             
             
             Scanner sc=new Scanner(System.in);
             System.out.println("请输入要删除学生的考号:");
              String examid=sc.next();
             
             
            try {
                //连接数据库
                Class.forName("oracle.jdbc.driver.OracleDriver");
                String strUrl="jdbc:oracle:thin:@localhost:1521:ORCL";        
                con=DriverManager.getConnection(strUrl,"test","test");
                
                
                
                Statement st=con.createStatement();
                String del="delete examstudent where examcard="+examid;
                int j=st.executeUpdate(del);
                if(j>0)
                {
                System.out.println("删除成功!");
                }else
                {
                    System.out.println("查无此人!请重新进入程序...");
                }
            
                
                
                st.close();
                
                
                    
                
            } catch (Exception e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
            
            finally
            {
                if(con!=null)
                {
                try {
                    con.close();
                } catch (SQLException e) {
                    // TODO 自动生成的 catch 块
                    e.printStackTrace();
                }
                }
            }
            
            
            
        }
    
    }

    运行结果:

  • 相关阅读:
    shared_ptr weak_ptr boost 内存管理
    _vimrc win7 gvim
    qt 拖放
    数学小魔术 斐波那契数列
    qt4 程序 移植到 qt5
    (转)字符串匹配算法总结
    c++11
    BM 字符串匹配
    编译qt5 demo
    c++ 类库 学习资源
  • 原文地址:https://www.cnblogs.com/miss123/p/5602641.html
Copyright © 2011-2022 走看看