插入记录时在JDBC Java中获取错误

插入记录时在JDBC Java中获取错误,java,mysql,oracle,jdbc,Java,Mysql,Oracle,Jdbc,我正在编写一个Java JDBC代码来输入表中的记录,但是我得到一个错误Java.sql.SQLException:ORA-01438:值大于此列允许的指定精度。据我所知,我在语句int result=pst.executeUpdate()中的class StudentDAO中遇到了一个错误这是我的代码 package com.wipro.dao; import java.sql.Connection; import java.sql.PreparedStatement; import c

我正在编写一个Java JDBC代码来输入表中的记录,但是我得到一个错误Java.sql.SQLException:ORA-01438:值大于此列允许的指定精度。据我所知,我在语句int result=pst.executeUpdate()中的class StudentDAO中遇到了一个错误这是我的代码

 package com.wipro.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;

import com.wipro.util.DBUtil;
import com.wipro.util.Student;

//Crud operation logic
public class StudentDAO {

    public String insertStudent(Student Student17){
        String output = "fail";
        try{

            Connection conn = DBUtil.getDBConnection();
            PreparedStatement pst = conn.prepareStatement("insert into Student17(stdid,name,sub1,sub2,sub3,total,avg) values(?,?,?,?,?,?,?)");
            pst.setInt(1, Student17.getStdid());
            pst.setString(2, Student17.getName());
            pst.setInt(3, Student17.getSub1());
            pst.setInt(4, Student17.getSub2());
            pst.setInt(5, Student17.getSub3());
            pst.setInt(6, Student17.getTotal());
            pst.setInt(7, Student17.getAvg());

            //System.out.println("Output===== " + Student17.getTotal());
            //System.out.println("Output===== " + Student17.getAvg());

            //System.out.println("Output===== " + Student17.getName());

            //System.out.println("Output===== " + Student17.getSub1());

            //System.out.println("Output===== " + Student17.getSub2());

            //System.out.println("Output===== " + Student17.getSub3());

            int result = pst.executeUpdate(); 
            if(result != 0){
                output = "Success";
            }
            conn.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return output;
    }

}

package com.wipro.service;

import com.wipro.dao.StudentDAO;
import com.wipro.util.Student;

public class StudentService {
    public String InsertStudentService(Student Student17){
        String result = "Validation Error";
        if(Student17.getStdid()==0||Student17.getName()==null||Student17.getSub1()<=0||Student17.getSub2()<=0||Student17.getSub3()<=0)
            return result;
        else{
            int total  = Student17.getSub1() + Student17.getSub2() + Student17.getSub3();
            Student17.setTotal(total);
            Student17.setAvg(total/3);
            StudentDAO studentdao = new StudentDAO();
            studentdao.insertStudent(Student17);
            result = studentdao.insertStudent(Student17);
            return result;
        }
    }
}


package com.wipro.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBUtil {

    public static Connection getDBConnection() {
        Connection conn = null;
        try{
        Class.forName("oracle.jdbc.driver.OracleDriver");         

        conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","oracle");  

        }catch(Exception e){
            e.printStackTrace();
        }
        return conn;
    }

}

package com.wipro.util;

public class Student {
    private int stdid;
    private String name;
    private int sub1, sub2, sub3;
    private int total;
    private int avg;


    public void setStdid(int stdid) {
        this.stdid = stdid;
    }
    public int getStdid() {
        return stdid;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getSub1() {
        return sub1;
    }
    public void setSub1(int sub1) {
        this.sub1 = sub1;
    }
    public int getSub2() {
        return sub2;
    }
    public void setSub2(int sub2) {
        this.sub2 = sub2;
    }
    public int getSub3() {
        return sub3;
    }
    public void setSub3(int sub3) {
        this.sub3 = sub3;
    }
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    public int getAvg() {
        return avg;
    }
    public void setAvg(int avg) {
        this.avg = avg;
    }

}


package com.wipro.main;

import com.wipro.service.StudentService;
import com.wipro.util.Student;

public class MainClass {
    public static void main(String[] args){
        Student Student17 = new Student();

        Student17.setStdid(10);
        Student17.setName("karan");
        Student17.setSub1(80);
        Student17.setSub2(90);
        Student17.setSub3(100);

        StudentService service = new StudentService();
        String result = service.InsertStudentService(Student17);
        System.out.println("Output: "+ result);

    }
}
据我所知,我在语句int result=pst.executeUpdate()中的class StudentDAO中遇到了一个错误
感谢您的帮助。提前谢谢

问题出在sub3中,因为是3位数

create table Student17(
    stdid number(3) primary key,
    name varchar2(100),
    sub1 number(2),
    sub2 number(2),
    sub3 number(2),
    total number(3),
    avg number(3)
); 
sub3 number(2)

然后在代码上,更改如下:
Student17.setSub3(100)

O我认为信息非常清楚。你给一个列添加了一个太大的值…并且查看表定义(因为你没有发布它,所以我们不能这样做),你应该能够确定它是哪一列。这是我用来创建表的SQL命令-create table Student17(stdid number(3)主键,name varchar2(100),sub1 number(2),sub2 number(2),sub3 number(2)总数(3),平均数(3);那么,您希望如何在两位数列
sub3
中插入100(如
Student17.setSub3(100);
)?谢谢您的“piet.t”。我更改了号码,但现在发现错误java.sql.SQLException:ORA-00001:unique约束(SYSTEM.SYS\u C004025)被违反。但是记录正在插入。谢谢你,edu。我更改了号码,但现在我发现了错误java.sql.SQLException:ORA-00001:unique constraint(SYSTEM.SYS\u C004025)violated@tj_lucas这可能是因为您已经在表中插入了一条学生id为
10
的记录。只需更改id,然后再次运行。
create table Student17(
    stdid number(3) primary key,
    name varchar2(100),
    sub1 number(2),
    sub2 number(2),
    sub3 number(2),
    total number(3),
    avg number(3)
); 
sub3 number(2)