How to map java objects to Oracle datatypes [message #472594] |
Sun, 22 August 2010 21:51 |
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 #472784 is a reply to message #472594] |
Mon, 23 August 2010 21:12 |
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.
|
|
|
|
|
|
|