JDBC作业1
时间:2021-07-01 10:21:17
帮助过:2人阅读
*;
import java.util.Scanner;
public class Homework {
public static void main(String
[] args) {
// TODO 自动生成的方法存根
Scanner sc=new Scanner(System.
in);
Connection con=null;
System.out.println("请输入学生Type:");
int type
=sc.nextInt();
System.out.println("请输入学生IDCard:");
String idcard=sc.
next();
System.out.println("请输入学生ExamCard:");
String examcard=sc.
next();
System.out.println("请输入学生StudentName:");
String studentname=sc.
next();
System.out.println("请输入学生Location:");
String location=sc.
next();
System.out.println("请输入学生 Grade:");
int grade
=sc.nextInt();
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String strUrl="jdbc:oracle:thin:
@localhost:
1521:ORCL";
con=DriverManager.getConnection(strUrl,"test","test");
PreparedStatement ps=con.prepareStatement("
insert into examstudent e
values(xulie.nextval,?,?,?,?,?,?)");
ps.setLong(1, type);
ps.setString(2, idcard);
ps.setString(3, examcard);
ps.setString(4, studentname);
ps.setString(5, location);
ps.setLong(6, grade);
ps.executeUpdate();
System.out.println("信息录入成功!");
ps.close();
}catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
finally
{
if(con
!=null)
{
try {
con.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}
}
运行结果:
JDBC作业1
标签: