Reputation: 137
i'm new to oracle and java. I'm trying to understand why my code isn't working. Each time when i execute the last bit of code, i get that error. I've been trying to understand why i get it for quite some time, but i can't solve it. There's only one SELECT statement in this code. I think there aren't any mistakes there. Code from WageK.java:
import java.sql.*;
public class wage
{
public static void getWage
(int wage_id, java.lang.String[] w_name, java.lang.String[] w_lname,
int[] w_wage, int[] w_month, int[] wage_calc)
throws SQLException
{
try
{
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "Select name, last_name, wage,
n_month, Value(A).wage_calc() as your_wage" +"From wage_java A" +
"Where A.ID = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, wage_id);
rs = pstmt.executeQuery();
if (rs.next())
{
w_name[0] = rs.getString("name");
w_lname[0] = rs.getString("last_name");
w_wage[0] = rs.getInt("wage");
w_month[0] = rs.getInt("n_month");
wage_calc[0] = rs.getInt("wage_calc");
}
else
{
w_name[0] = "0";
w_lname[0] = "0";
w_wage[0] = 0;
w_month[0] = 0;
wage_calc[0] = 0;
}
}
catch (SQLException e) {System.err.println(e.getMessage());}
}
}
Then i was publishing the PL/SQL wrapper using this code.
Create or replace procedure getWage (wage_id IN NUMBER, w_name OUT VARCHAR2,
w_lname OUT VARCHAR2, w_wage OUT NUMBER, w_month OUT NUMBER,
wage_calc OUT NUMBER) AS language Java name 'WageK.getWage
(int, java.lang.String[],java.lang.String[],int[], int[], int[])';
But when i try to access it using this code, it gives me that error:
set serveroutput ON;
call DBMS_JAVA.SET_OUTPUT(2000);
declare
w_name VARCHAR2(20);
w_lname VARCHAR2(20);
w_wage Number;
w_month Number;
wage_calc Number;
BEGIN
getWage(1, w_name, w_lname, w_wage, w_month, wage_calc);
dbms_output.Put_line('Wages of employee's:');
dbms_output.Put_line(' ' || wage_calc);
end;
Any help regarding my issue would be greatly appreciated.
Upvotes: 2
Views: 17758
Reputation: 1269543
You should print out the string after it is created. At least some of the problems would be obvious, such as:
Select name, last_name, wage,
n_month, Value(A).wage_calc() as your_wageFrom wage_java AWhere A.ID = ?;
In other words, you need spaces in the string, something like this:
String sql = "Select name, last_name, wage, n_month, Value(A).wage_calc() as your_wage " +
"From wage_java A " +
"Where A.ID = ?";
Upvotes: 2