• jdbc练习1


    package test_1;
    import java.sql.*;
    import java.util.Scanner;
    public class lianxi {
    
    	public static void main(String[] args) {
    		Scanner sc= new Scanner(System.in);
    	    System.out.println("请输入考生信息");
    	    System.out.println("Type:");
    	    String t=sc.next();
    	    System.out.println("IDCard:");
    	    String id=sc.next();
    	    System.out.println("ExamCard:");
    	    String card=sc.next();
    	    System.out.println("StudentName:");
    	    String sn=sc.next();
    	    System.out.println("Location:");
    	    String lt=sc.next();
    	    System.out.println("Grade:");
    	    String g=sc.next();
    	    System.out.println("信息录入成功!");
    	    //连接数据库
    	    Connection  con=null;
    	    try
    	    {
    	    	Class.forName("oracle.jdbc.driver.OracleDriver");
    	    
    	    	String  struil="jdbc:oracle:thin:@localhost:1521:ORCLER";
    	    
    	    	con=DriverManager.getConnection(struil, "test", "asd123");
    	    	System.out.println("连接数据库成功");
    	    String sql="insert into examstudent(flowid,type,idcard,examcard,studentname,location,grade) values (lianxi.nextval,?,?,?,?,?,?)";
    	    PreparedStatement  ps=con.prepareStatement(sql);
    	    ps.setString(1, t);
    	    ps.setString(2, id);
    	    ps.setString(3, card);
    	    ps.setString(4, sn);
    	    ps.setString(5, lt);
    	    ps.setString(6, g);
    	    ps.executeUpdate();
    	    ps.close();
    	    
    	    
    	    }
    	    catch(Exception e)
    	    {
    	    	e.printStackTrace();
    	    	System.out.println("连接数据库失败");
    	    }
    
    
    	}
    

  • 相关阅读:
    [LeetCode] 143. 重排链表
    [LeetCode] 342. 4的幂
    [LeetCode] 1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗?
    [LeetCode] 148. 排序链表
    [LeetCode] 525. 连续数组
    [LeetCode] 160. 相交链表
    [LeetCode] 134. 加油站
    [LeetCode] 474. 一和零
    CentOS 升级 OpenSSH
    AWS 证书取消挂靠
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5602523.html
Copyright © 2020-2023  润新知