Home » Developer & Programmer » JDeveloper, Java & XML » How to map java objects to Oracle datatypes
How to map java objects to Oracle datatypes [message #472594] Sun, 22 August 2010 21:51 Go to next message
rc_oli
Messages: 4
Registered: August 2010
Location: Philippines
Junior Member
I have created a java method that returns an object
Example:

EmployeeInfo
Name
Gender
Marital Status

in my java method, this

public EmployeeInfo Search (String idnum)
.....

return ei;


In my PL/SQL function, I already created a user defined object having the same properties as to my java class object.

The question is, what kind of datatype I should use from java so that when I will pass this to oracle, the dataype will be mapped correctly?
Re: How to map java objects to Oracle datatypes [message #472595 is a reply to message #472594] Sun, 22 August 2010 22:28 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>In my PL/SQL function, I already created a user defined object having the same properties as to my java class object.
>The question is, what kind of datatype I should use from java so that when I will pass this to oracle, the dataype will be mapped correctly?

Above implies that what ever you tried did not work.
It is really, Really, REALLY difficult to fix a problem that can not be seen.
use COPY & PASTE so we can see what you do & how Oracle responds.

It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/
Re: How to map java objects to Oracle datatypes [message #472612 is a reply to message #472595] Mon, 23 August 2010 00:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Database JDBC Developer's Guide and Reference
Chapter 15 Working with Oracle Object Types

Regards
Michel
Re: How to map java objects to Oracle datatypes [message #472784 is a reply to message #472594] Mon, 23 August 2010 21:12 Go to previous messageGo to next message
rc_oli
Messages: 4
Registered: August 2010
Location: Philippines
Junior Member
below are my codes

JAVA:

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "EmployeeInfo" AS
public class EmployeeInfo{
private String employeeID;
private String lastName;
private String firstName;
private String emailAddress;
private String emailDestination;
private String contactNumber;

public String getEmployeeID() {
return employeeID;
}
public void setEmployeeID(String employeeID) {
this.employeeID = employeeID;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getEmailDestination() {
return emailDestination;
}
public void setEmailDestination(String emailDestination) {
this.emailDestination = emailDestination;
}
public String getContactNumber() {
return contactNumber;
}
public void setContactNumber(String contactNumber) {
this.contactNumber = contactNumber;
}
}
/


CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED PDK."EmployeeDirectory" AS
import java.util.Properties;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import EmployeeInfo.*;

public class EmployeeDirectory {
private EmployeeInfo empInfo;
private DirContext dirCtx;
private boolean connected=false;

public void connect() throws NamingException{
Properties env = new Properties();
env.put(DirContext.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(DirContext.PROVIDER_URL,"ldap://localhost:389");
this.dirCtx = new InitialDirContext(env);
this.connected=true;
}

public EmployeeInfo Search(String employeeID) throws Exception{
String filter = "(&(idnumber="+employeeID+"))";
SearchControls sc = new SearchControls();
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration ne = this.dirCtx.search("ou=person, o=edu, c=PH", filter, sc);
empInfo = new EmployeeInfo();
while (ne.hasMore()) {
SearchResult sr = (SearchResult) ne.next();
Attributes attrs = sr.getAttributes();
empInfo.setEmployeeID(attrs.get("idnumber").toString().substring(10));
empInfo.setFirstName(attrs.get("firstname").toString().substring(11));
empInfo.setLastName(attrs.get("sn").toString().substring(4));
empInfo.setEmailAddress(attrs.get("mail").toString().substring(6));
empInfo.setEmailDestination(attrs.get("emailDestination").toString().substring(18));
empInfo.setContactNumber(attrs.get("extension").toString().substring(11));
}
return empInfo;
}

public EmployeeInfo getEmpInfo() {
return empInfo;
}

public void setEmpInfo(EmployeeInfo empInfo) {
this.empInfo = empInfo;
}

public boolean isConnected() {
return connected;
}

public void setConnected(boolean connected) {
this.connected = connected;
}

public DirContext getDirCtx() {
return dirCtx;
}

public void setDirCtx(DirContext dirCtx) {
this.dirCtx = dirCtx;
}
}
/


PL/SQL Code:

CREATE OR REPLACE PACKAGE PDK.SEARCHEMPLOYEEID AS

FUNCTION SearchEmployeeID(Param1 VARCHAR2)
return PERSONNELRECTYPE
AS
LANGUAGE java
NAME 'EmployeeDirectory.Search(java.lang.String) return EmployeeInfo;


User Defined Types:
CREATE OR REPLACE TYPE PersonnelRec AS OBJECT(
employeeID varchar2(10),
lastName varchar2(255),
firstName varchar2(255),
emailAddress varchar2(255),
emailDestination varchar2(255),
contactNumber varchar2(255));
/

CREATE OR REPLACE TYPE PersonnelRecType AS TABLE OF PersonnelRec
/



I appreciate any help

Thanks.


Re: How to map java objects to Oracle datatypes [message #472809 is a reply to message #472784] Tue, 24 August 2010 01:09 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Did you read the link I provided?

Regards
Michel
Re: How to map java objects to Oracle datatypes [message #472813 is a reply to message #472809] Tue, 24 August 2010 01:28 Go to previous messageGo to next message
rc_oli
Messages: 4
Registered: August 2010
Location: Philippines
Junior Member
Michel Cadot wrote on Tue, 24 August 2010 14:09
Did you read the link I provided?

Regards
Michel



Sorry Michael, I am just new to java via oracle. do you have any solution?
Re: How to map java objects to Oracle datatypes [message #472823 is a reply to message #472813] Tue, 24 August 2010 01:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Maybe the one that is in the link I provided.

Regards
Michel
Re: How to map java objects to Oracle datatypes [message #472826 is a reply to message #472823] Tue, 24 August 2010 01:58 Go to previous message
rc_oli
Messages: 4
Registered: August 2010
Location: Philippines
Junior Member
Michel Cadot wrote on Tue, 24 August 2010 14:56
Maybe the one that is in the link I provided.

Regards
Michel



thanks Michael, I will try it
Previous Topic: OracleFailoverEventHandler vs OracleHAEventHandler
Next Topic: DOM parsing
Goto Forum:
  


Current Time: Fri Apr 19 00:39:38 CDT 2024