Java实现手动输入修改数据库_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);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值