day33-1-1用java的jdbc添加数据库中表的内容(手动输入内容)

package cn.wang.jdbc;

import zuoye.zuoye;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class zuoyetext {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Scanner sc1=new Scanner(System.in);
System.out.println("请输入员工的id");
int s = sc1.nextInt();
System.out.println("请输入员工的名字");
String s1 = sc.nextLine();
System.out.println("请输入员工的职务id");
int s2 = sc1.nextInt();
System.out.println("请输入上级领导");
int s3 = sc1.nextInt();
System.out.println("请输入入职日期");
String s4 = sc.nextLine();
System.out.println("请输入工资");
String s5 = sc.nextLine();
System.out.println("请输入奖金");
String s6 = sc.nextLine();
System.out.println("所在部门编号");
int s7 = sc1.nextInt();
Connection c =null;
PreparedStatement pre=null;
ResultSet re=null;
try {
c = zuoye.getConnection();
String s9 = "insert into emp values("+s+",'"+s1+"',"+s2+","+s3+",'"+s4+"','"+s5+"','"+s6+"',"+s7+")";
pre = c.prepareStatement(s9);
int i = pre.executeUpdate(s9);
if (i>0){
System.out.println("添加成功");
}else{
System.out.println("添加失败");
}
} catch (Exception e) {
e.printStackTrace();
}finally {
zuoye.a(c,pre,re);
}


}
}
原文地址:https://www.cnblogs.com/hfew/p/10640374.html