How to insert a java object int derby database
hi,
i have a problem , ie..i want to insert my java object int database derby.and also i need to retrieve that object from database whenever i need. Any body help me to do that in derby...
Thanks
Or you would design a table where the columns of the table correspond to attributes of the object. Then you would make a row by writing out the attributes to the columns they correspond to.
Similar Messages
-
How can I include Java objects in a 'Database Export'?
I am running a 'Database Export' to produce a DDL script for all objects in the schema.
I have some objects of type JAVA SOURCE and JAVA CLASS in my schema, but they are not included in the DDL script. Is there a way to get them included?
Version is 3.0.04.
Thanks,
MikeAny suggestions on this?
Thanks,
Mike -
XSLT - How to pass a Java object to the xslt file ?
Hi ,
I need help in , How to pass a java object to xslt file.
I am using javax.xml.transform.Tranformer class to for the xsl tranformation. I need to pass a java object eg
Class Employee {
private String name;
private int empId;
public String getName() {
return this.name;
public String getEmpId() {
return this.empId;
public String setName(String name) {
this.name = name;
public String setEmpId(int empId){
this.empId = empId;
How can i access this complete object in the xsl file ? is there any way i can pass custom objects to xsl using Transformer class ?This is elementary. Did you ask google ? http://www.google.com/search?q=calling+java+from+xsl
ram. -
How to retrieve the java object in a proxy service in osb -- Plz help
Hi all,
I have a singleton java class which runs whenever the weblogic server gets started and store the output in its object. I need to access this java object from a proxy service in osb.
We tried using java call out and retrieved that object but we couldn't know how to parse that object into XML.
We are not sure of using the java call out in osb to solve this purpose because whenever we use a java callout, that particular java code will run which is not the case of singleton class.
So kindly help us how to retrieve the java object which holds the output without running the java code every time because its already run and holding the output in its object.
Regards
Prabhuhere the doc http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/context.html#wp1106656
but I guess you are already at the stage of getting a POJO in a first Java Callout and passing the POJO to a second Java Callout, which should then return it to OSB as a XMLObject.
My recommendation is to write a Java function which returns a XMLObject and uses a XMLCursor to populate it with the values of the POJO.
An XMLObject returned to the OSB is automatically transformed in a "XML" variable (which in reality is represented as a XMLObject in the Pipeline context)
Here some code sample:
http://www.javamonamour.org/2010/09/how-to-create-xmlobject-using-xmlcursor.html -
How to instantiate a java object (using JNI)?(n'more)
hey bschauwe, thanks for your last post, you were guessing but your 4th guess was right on the money of how id like to do it.
"4. An alternative way to return data to java from C is to instantiate a java object (using JNI), then use JNI to call that object's setters, then return the object at the end of the C routine."
I know now how to get the object's setters, I am just unsure how to instantiate a java object from the native C code using JNI. Also you said to returnt he object at the end of the c routine, that is just a good ol' return statement right? no other functions to release memory or anything are needed? So basically it would be something like:
JNIEXPORT jobject retObj JNICALL Java_AbfaRegion_getJSourceData
(JNIEnv *env, jobject thisObj)
//instantiate the java object on retObj????
//call setters with values from the c structures...
//return retObj??? no other memory releasing needed?
}Thanks again for all your help,
ShaneK sounds straight forward enough, the index in my book had nothing on <init> and I wasnt aware of the NewObject call. So my final (well for demonstration purposes) code should look something like:
JNIEXPORT jobject retObj JNICALL Java_AbfaRegion_getJSourceData
(JNIEnv *env, jobject thisObj)
jclass clazz;
jclass clazzTemp;
jmethodID mid;
jint val;
jobject tempObj;
//first instanciate the object
clazz = (*env)->GetObjectClass(env, retObj);
mid = (*env)->GetMethodID(env, clazz, "<init>", "()V");
//Get Object
tempObj = (*env)->NewObject(env, clazz, mid);
//get Class reference to instantiated class
clazzTemp = (*env)->GetObjectClass(env, tempObj);
//Start calling setters to set the object up.
mid = (*env)->GetMethodID(env, clazzTemp, "SetHeight", "(I)V");
(*env)->CallVoidMethod(env,tempObj, mid, struct->myHeight);
//set more members ...
//return the object back to java with its members filled out.
//before returning do I need to call (*env)->DeleteLocalRef(tempObj); ??
return tempObj;
}So is this how i do it for a function that is nativly defined as:
public native JSources getJSourceData();?
if this is right, then im cooking, and cannot thank you enough!
-Shane -
How to insert a image file into oracle database
hi all
can anyone guide me how to insert a image file into oracle database now
i have created table using
create table imagestore(image blob);
but when inserting i totally lost don't know what to do how to write query to insert image fileHi I don't have time to explain really, I did have to do this a while ago though so I will post a code snippet. This is using the commons file upload framework.
Firstly you need a multi part form data (if you are using a web page). If you are not using a web page ignore this bit.
out.println("<form name=\"imgFrm\" method=\"post\" enctype=\"multipart/form-data\" action=\"FileUploadServlet?thisPageAction=reloaded\" onSubmit=\"return submitForm();\"><input type=\"FILE\" name=\"imgSource\" size='60' class='smalltext' onKeyPress='return stopUserInput();' onKeyUp='stopUserInput();' onKeyDown='stopUserInput();' onMouseDown='noMouseDown(event);'>");
out.println(" <input type='submit' name='submit' value='Submit' class='smalltext'>");
out.println("</form>"); Import this once you have the jar file:
import org.apache.commons.fileupload.*;Now a method I wrote to upload the file. I am not saying that this is correct, or its the best way to do this. I am just saying it works for me.
private boolean uploadFile(HttpServletRequest request, HttpSession session) throws Exception {
boolean result = true;
String fileName = null;
byte fileData[] = null;
String fileUploadError = null;
String imageType = "";
String error = "";
DiskFileUpload fb = new DiskFileUpload();
List fileItems = fb.parseRequest(request);
Iterator it = fileItems.iterator();
while(it.hasNext()){
FileItem fileItem = (FileItem)it.next();
if (!fileItem.isFormField()) {
fileName = fileItem.getName();
fileData = fileItem.get();
// Get the imageType from the filename extension
if (fileName != null) {
int dotPos = fileName.indexOf('.');
if (dotPos >= 0 && dotPos != fileName.length()-1) {
imageType = fileName.substring(dotPos+1).toLowerCase();
if (imageType.equals("jpg")) {
imageType = "jpeg";
String filePath = request.getParameter("FILE_PATH");
session.setAttribute("filePath", filePath);
session.setAttribute("fileData", fileData);
session.setAttribute("fileName", fileName);
session.setAttribute("imageType", imageType);
return result;
} And now finally the method to actually write the file to the database:
private int writeImageFile(byte[] fileData, String fileName, String imageType, String mode, Integer signatureIDIn, HttpServletRequest request) throws Exception {
//If the previous code found a file that can be uploaded then
//save it into the database via a pstmt
String sql = "";
UtilDBquery udbq = getUser(request).connectToDatabase();
Connection con = null;
int signatureID = 0;
PreparedStatement pstmt = null;
try {
udbq.setUsePreparedStatements(true);
con = udbq.getPooledConnection();
con.setAutoCommit(false);
if((!mode.equals("U")) || (mode.equals("U") && signatureIDIn == 0)) {
sql = "SELECT SEQ_SIGNATURE_ID.nextval FROM DUAL";
pstmt = con.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()) {
signatureID = rs.getInt(1);
if (fileName != null && imageType != null) {
sql = "INSERT INTO T_SIGNATURE (SIGNATURE_ID, SIGNATURE) values (?,?)";
InputStream is2 = new ByteArrayInputStream(fileData);
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, signatureID);
pstmt.setBinaryStream(2, is2, (int)(fileData.length));
pstmt.executeUpdate();
pstmt.close();
con.commit();
con = null;
if(mode.equals("U") && signatureIDIn != 0) {
signatureID = signatureIDIn.intValue();
if (fileName != null && imageType != null) {
sql = "UPDATE T_SIGNATURE SET SIGNATURE = ? WHERE SIGNATURE_ID = ?";
InputStream is2 = new ByteArrayInputStream(fileData);
pstmt = con.prepareStatement(sql);
pstmt.setBinaryStream(1, is2, (int)(fileData.length));
pstmt.setInt(2, signatureID);
pstmt.executeUpdate();
pstmt.close();
con.commit();
con = null;
} catch (Exception e) {
con = null;
throw new Exception(e.toString());
return signatureID;
} -
How to insert Integer array in a MySql DataBase
Now i am doing one swing application,in that i have List box,My doubt is ,How to insert the mutiple seleted value into database.
http://java.sun.com/docs/books/tutorial/jdbc/
-
How to insert an image file in Oracle database
hi
can you please tell me how to insert an image file into oracle database????
suppose there is one image file in c:\pictures\rose.jpg. how to insert that file into database? theoretically i know that will be BFILE type but i dont know how to insert that.
will be waiting for your reply........
thanks & regards,
PriyatoshHello,
The easiest way to load a blob is to use SQL loader.
This example comes from the utilities guide:
LOAD DATA
INFILE 'sample.dat'
INTO TABLE person_table
FIELDS TERMINATED BY ','
(name CHAR(20),
1 ext_fname FILLER CHAR(40),
2 "RESUME" LOBFILE(ext_fname) TERMINATED BY EOF)
Datafile (sample.dat)
Johny Quest,jqresume.txt,
Speed Racer,'/private/sracer/srresume.txt',
Secondary Datafile (jqresume.txt)
Johny Quest
500 Oracle Parkway
Secondary Datafile (srresume.txt)
Loading LOBs
10-18 Oracle Database Utilities
Speed Racer
400 Oracle Parkway
regards,
Ivo -
How to insert varchar2 40000 englist char to database.
How to insert varchar2 40000 englist char to database use jdbc.
My table is ut(varchar2(4000));]
oracle version is 9.0Are you using the thin driver or the OCI driver? The Oracle Globalization Guide documents that the thin driver imposes more restrictive size limitations on character data than the Oracle database http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96529/ch9.htm#14068 You would need to ensure that you're using the OCI driver to work around these restrictions.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
How to add a ChartOfAccounts object into the database.
how to add a ChartOfAccounts object into the database. please shows sample code
thanksDim CoA As SAPbobsCOM.ChartOfAccounts
CoA = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oChartOfAccounts)
CoA.Code = 11223344
CoA.ExternalCode = "a1234"
CoA.ForeignName = "f Test Account"
CoA.Name = "Test Account"
CoA.AccountType = SAPbobsCOM.BoAccountTypes.at_Other
CoA.ActiveAccount = SAPbobsCOM.BoYesNoEnum.tYES
CoA.FatherAccountKey = 100001
If CoA.Add <> 0 Then
MessageBox.Show(oCompany.GetLastErrorDescription)
Else
MessageBox.Show("Added Account")
End If
Remember the father account key must be a valid account number in the company where you are trying to add the new account. (The G/L Account code seen in the SBO client) -
How to use the Java objects or methods in pl/sql function as a parameter
dear all,
I java object passed as a parameter in pl/sql. how can i access the java objects as parameter in pl/sql function. please give a soultion to me
mohan reddyI'm not sure whether this would help you.
Have a look at this program to list files from a directory.
CREATE GLOBAL TEMPORARY TABLE DIR_LIST
( FILENAME VARCHAR2(255) )
ON COMMIT DELETE ROWS
Table created.
create or replace
and compile java source named "DirList"
as
import java.io.*;
import java.sql.*;
public class DirList
public static void getList(String directory)
throws SQLException
File path = new File( directory );
String[] list = path.list();
String element;
for(int i = 0; i < list.length; i++)
element = list;
#sql { INSERT INTO DIR_LIST (FILENAME)
VALUES (:element) };
Java created.
SQL>
create or replace
procedure get_dir_list( p_directory in varchar2 )
as language java
name 'DirList.getList( java.lang.String )';
SQL> exec get_dir_list( 'C:\Bhagat' );
PL/SQL procedure successfully completed.
Thanks,
Bhagat -
How to create a Java Object dynamically
I want to convert a "DataObject (SDO) " into "Pure java object".
For this i want to create a java object with the fields in Dataobject, and this should be in generic way.I want to convert a "DataObject (SDO) "What is a "DataObject (SDO)"?
into "Pure
java object".What is a "Pure java object"?
For this i want to create a java object with the
fields in Dataobject, What is stopping you? Do you not know how do define a class? Do you think you can add fields to the Object class? If that's what you mean, you're out of luck.
and this should be in generic
way.What do you mean "in generic way"? "Generic" is a very generic term. There are lots of contexts in which it could apply and lots of different possible meanings for "generic way."
You'll have to explain your queston more clearly. -
How to pass the java object into the spring controller
Hi Friends
When I hit the url at the first time my call goes to the spring controller and sets the userDetails objects in the modelAndView.addObject("userDetails", userDetails.getUserDetails()) and returns the userDetails.html page. if I click any link in the same page i want to pass same (userDetails) object thru javascript or jquery and calls the another(controller) method and returns the same (userDetails.html) page.
It means how can i pass the java object thru javascript or jquery and calls the controller. if i get the same object in my controller i can avoid calling the db again. please help me out to resolve this issue. i am tired of fixing this issue.
Regards
Sherin PoojaIf you want to avoid calling the database again then cache the data.
However before you do that make sure that calling the database, in the context of YOUR system, is going to be an actual problem.
For example there is absolutely no point in caching a User object when only one user an hour is actually using the system. -
How to create new java objects in native methods?
Hello,
Is it possible to create java objects and return the same to the java code from a native method?
Also is it possible to pass java objects other than String objects (for example, Vector objects) as parameters to native methods and is it possible to return such objects back to the java code?
If so how can I access those objects (say for example, accessing Vector elements) inside the native code?
What should I do in order to achieve them?
Regards,
Satishbschauwe is correct in that constructing Java objects and calling methods on Java objects from native code is tough and takes some study. While you're at it, you might want to check out Jace, http://jace.reyelts.com/jace. It's a free open-source toolkit that really takes the nastiness out of doing this sort of stuff. For example,/**
* A C++ function that takes a java.util.Vector and plays around with it.
public void useVector( java::util::Vector& vector ) {
// Print out all the contents of the vector
for ( Iterator it = vector.iterator(); it.hasNext(); ) {
cout << it.next();
// Add some new elements to the vector
vector.addElement( "Hello" );
vector.addElement( "world" );
} All this code just results in calls to standard JNI functions like FindClass, NewObject, GetMethodID, NewStringUTF, CallObjectMethod, etc...
God bless,
-Toby Reyelts -
How to store java objects in the database
Hi,
I am trying to store HttpSession state across Application Servers. Basically I am trying to build a sort of application cluster server on my own. I thought the best way to do this was to periodically store the HttpSession object from an application server in a database.
I created a table in Oracle 8i with a blob column. I use a PreparedStatement.setObject() method to store the HttpSession object in the database. My problem is, I don't know how to get the object back from the database.
Since ResultSet.getBlob returns the Blob locator, I need to read the BinaryInputStream to get all my data back. This tells me that getBlob basically works only for things like files, and cannot be used for Java objects.
Is there any way around this? Your input would be much appreciated.
Regards,
Somaiah.Thanks for the quick reply vramakanth.
Do I have to use a type map if I do this? Also does such a type map exist for the HttpSession class?
Thanks,
Somaiah.
Maybe you are looking for
-
I'd like to carry my system, applications and files on a portable Thunderbolt ssd drive and boot from it. I have a Mac Pro in the office, iMac at home, a MacBook Air for when I'm on the road, all with TB. Can a single external TB drive boot all thr
-
Hi, Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production PL/SQL Release 11.2.0.2.0 - Production CORE 11.2.0.2.0 Production TNS for 32-bit Windows: Version 11.2.0.2.0 - Production NLSRTL Version 11.2.0.2.0 - Production My Scenar
-
How to handle scrap occured during processing
Hi all, I am facing problem with handling the scrap occured during processing. The case here is i want to scrap the material eg ABC, and want to sell the same material with different material no., unit of measurement. The present process is as below,
-
Wireless just stopped working..
Hi, My wireless used to work but not it just stopped working and it works sometimes but mostly not. I have three other mac laptops in my house and a few computers and they all work with the linksys router and they get on wireless fine. but when I
-
The TOC in my generated project is not navigating to the correct subfolders
The TOC in my generated project (Multiscreen HTML5/Andriod (Desktop) layout) is not opening to the correct sub folders. For example, when selecting a Level 1 folder (say the one highlighted in orange), it will jump to a Level 3 list of topics in a co