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();
            }
            }
        }
        
        
        
    }

}

运行结果:

原文地址:https://www.cnblogs.com/miss123/p/5602641.html