こんにちは、私は以下のようにデータを挿入するためにパッケージのプロシージャを書かれている:Oracleの数値または値のエラーPL/SQL
create or replace package Proj2_student_reg_package is
type data_cursor is ref cursor;
procedure add_students(sidIn IN students.sid%type, fnameIn IN students.firstname%type,
lnameIn IN students.lastname%type, statusIn IN students.status%type,
gpaIn IN students.gpa%type, emailIn IN students.gpa%type,
ret_message OUT varchar2);
end Proj2_student_reg_package;
/
create or replace package body Proj2_student_reg_package as
procedure add_students(sidIn IN students.sid%type, fnameIn IN students.firstname%type,
lnameIn IN students.lastname%type, statusIn IN students.status%type,
gpaIn IN students.gpa%type, emailIn IN students.gpa%type,
ret_message OUT varchar2)
is
begin
insert into students values(sidIn ,fnameIn,lnameIn,statusIn,gpaIn,emailIn);
COMMIT;
ret_message := 'Success';
EXCEPTION
WHEN OTHERS THEN
ret_message := 'Error';
end add_students;
end Proj2_student_reg_package;
を、私は、Javaプログラムから呼び出しています:
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Scanner;
import oracle.jdbc.OracleTypes;
import oracle.jdbc.pool.OracleDataSource;
public class AddStudent {
public void addStudent(){
Scanner line = new Scanner(System.in);
try
{
//Connection to Oracle server
OracleDataSource ds = new oracle.jdbc.pool.OracleDataSource();
ds.setURL("jdbc:oracle:thin:@localhost:1521:xe");
Connection conn = ds.getConnection("*****", "****");
System.out.print("Enter the sid: ");
String sid = line.next();
System.out.print("Enter first name: ");
String fname = line.next();
System.out.print("Enter last name: ");
String lname = line.next();
System.out.print("Enter status: ");
String status = line.next();
System.out.print("Enter gpa: ");
String gpa = line.next();
System.out.print("Enter email: ");
String email = line.next();
CallableStatement cs = conn.prepareCall("{call Proj2_student_reg_package.add_students(?,?,?,?,?,?,?)}");
cs.setString(1, sid);
cs.setString(2, fname);
cs.setString(3, lname);
cs.setString(4, status);
cs.setString(5, gpa);
cs.setString(6, email);
cs.registerOutParameter(7, Types.VARCHAR);
cs.executeQuery();
System.out.println(cs.getString(7));
cs.close();
//line.close();
}
catch (SQLException e) { System.out.println("SQLException " + e.getMessage());}
catch (Exception e) {System.out.println(e);}
}
}
私の学生のテーブルには、次のとおりです。私は、SIDとしてJavaプログラムから値を与えている
create table students (sid char(4) primary key check (sid like 'B%'),
firstname varchar2(15) not null, lastname varchar2(15) not null, status varchar2(10)
check (status in ('freshman', 'sophomore', 'junior', 'senior', 'graduate')),
gpa number(3,2) check (gpa between 0 and 4.0), email varchar2(20) unique);
:B987, fname : akki, lname : aror, satus : junior , gpa : 3,email : [email protected]
しかし、これは私にエラーを与えている:
SQLException ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 1
は、私があまりにも多くを見つけることを試みたが、間違いがある場合、私は把握できませんでした。 誰でも私に間違いを教えて、エラーを修正するのに役立つことができます。あなたのCallableStatement
cs
オブジェクトで
「sid」は 'char(4)'ですが、5文字の文字列を送信しようとしています。それはこの特定のエラーを引き起こすかもしれませんが、それは問題になるでしょう。 –
また、ポストのコードとデータを適切にフォーマットするには時間をかけてください。誰かの助けを求めるときは、彼らがあなたを助けてくれるようにしてください。 –
@ジムガリソン私は間違って入力しました。私はB987としてsidで送信しています。 – Akshay