How to dynamically configure JPA setting at runtime using java code?
Hi,
I am new to EJB 3.0 and JPA. I am trying to help my company to deploy the use of JPA in EJB3.0. Currently, i am trying out with OpenJPA in IBM Webshpere Application Server 7.0. We have four different WAS servers running for testing, system integration testing, user testing and production respectively, and in each region, the configurations for data source, JDBC username and password, schema, etc are different. So i think i would need to configure the JPA setting during runtime using Java code that determines which is the environment. And apparently i am stuck with the limited knowledge i have.
1) I understand that i could override the JDBC in the persistence xml by creating entity manager using entity manager factory. But is it possible that i do similar thing by using inejction of persistence context on entity manager to obtain a container managed entity manager?
2) Alternatively, it is possible to create multiple persistence unit in the XML and inject different PU to the entity manager, am i right? But how to inject dynamically since @PersistenceContext(unitName="xxx") only accepts constant declaration.
3) Is it possible that the JDBC username and password are read from properties file?
Thanks for your help in advance!
Hi
Thanks for the reply.
Are you saying that i have to configure the data source authentication to the backend DB2 using the JAAS-J2C? Correct me if i am mistaken. I guess i am unable to do so as the application server setup only contains one data source, and the server hosted a number of applications. Every applications has their own JDBC username and password supply to the data source (the ID supplied at the DB2 side will decide which resource can access) and thus, i have to supply the username and password at runtime. Talked to the server guy and seems that it is not feasible to have seperate datasource for each applications as considered to the volume of applications hosted inside the server.
Any suggestion?
Similar Messages
-
How can we get requester's user id using java code
Hi,
How can we get requester's user id using java code?
eg: If i had logged in as xelsysadm and request a resource for user uid101 on the userid field it should display uid101 and not xelsysadm.
also,
I have a resoure "A" which on revoking should also revoke resources B and C. How can it be done. Resource A, B, and C are 3 different resource objects.
==Thanks,
dokiOk, so there is a way, but it's not available during submission. You can use the findRequests api. From the result set, get the "Requests.Consolidated Data Value" value. In this information, you will get an xml formatted data. It provides the list of users on the request on the left side after submission. After the request is completed, this value is available. Upon completion, you could get the request information, get this value, and parse the information for user ids.
In the same adapter, use the following API:
formIntf.setObjectFormData(objInstanceKey, formHash)
The formHash is a hashtable containing the field name on your object form, and the values you wish to populate it with. You could create a textarea box on your object form and populate the userids for who the request is for.
However, this makes absolutely 0 sense. When you get a request, the list of userids are listed right there on the request.
-Kevin -
How to send sms to mobile from tomcatserver using java code?
Hi,
Could you please let me know that,
How to send sms to mobile from tomcatserver using java code? Please provide the code snippet.
Thanks in advance.Yes, but something needs to send that message. You can't just take an arbitrary computer and send an SMS, it does not have the hardware to do that.
So either you have a mobile through which you do that or more likely - you use some sort of online service to do it. Whatever choice you make will determine what code you will have to write to get it done. Nobody is going to deliver the code to you, that's your job. It is also your job to figure out what service you are going to use. -
How to create multiple component instances at runtime using java
Hi,
I need to create component instances at runtime using java.I found ComponentSet.add method.But I am not finding a way to get handle of ComponentSet.
I see methods with params of IRuntimeNode.But how to get ComponentSet from IRuntimeNode.
If anybody knows or have sampel code then please share with me.
thanks,
ashokAshok --
This is a common challenge for those using Configurator Extensions with multiple instantiation for the first time. The problem is that the CIO's representation of the structure for multiply-instantiable Components differs slightly from what both Configurator Developer users and Configurator Runtime users see in those respective applications. Multiply-instantiable Components are not direct children of the Model in which they're defined. Internally, there is an entity that sits between the parent Model and the instantiable Components; that intermediate entity is the ComponentSet object you've found in the CIO documentation.
If the name of your multiply-instantiable Component is "My Component", then its ComponentSet may be accessed simply by calling getChildByName("My Component") on its parent Model; a List of the instantiated Components may be accessed with the ComponentSet's getChildComponentNodes() method, and instances may be added and deleted using its add() and delete() methods.
Hope this helps.
Eogan -
How to launch Jar file in Mac Os using java code??
can anyone tell me how can i launch another jar file in my apllication using java code.
define "launch".
- You want to run a new java program in a separate process? (see Runtime.exec())
- You want to run a method in a specific class in the jar? (add jar to application classpath and then simply instantiate the class and call the method) -
How to create a table in the file using java code.?
HI,
I should export the data from the view objects to a word document. I have done that but I should
display the data in the form of a table.
Kindly come up with the necessary information on how to create a table in the file using java.
Thanks,
PhaniHi, Thank you for responding to my query.
The below are the details of my code.
DCBindingContainer dcBindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding StudentDetailsContent =
(DCIteratorBinding)dcBindings.get("StudentView1Iterator");
OutputStreamWriter w = new OutputStreamWriter(outputStream, "UTF-8");
Row currentRow =
StudentDetailsContent.getRowSetIterator().first();
Object a[]= currentRow.getAttributeValues();
int i;
for(i=0 ;i<=a.length;i++){
w.write(a.toString());
w.write(" ");
w.flush();
I am usning this coding to achieve the task of exporting data to file.
I need to display this information in the table that is where I need help from you people.
Thanks, -
How to read data from the excel file using java code.
Hi to all,
I am using below code to getting the data from the excel file but I can't get the corresponding data from the specific file. can anyone give me the correct code to do that... I will waiting for your usefull reply......
advance thanks....
import java.io.*;
import java.sql.*;
public class sample{
public static void main(String[] args){
Connection connection = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection( "jdbc:odbc:Mydsn","","" );
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
System.out.println("sample:"+rs);
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("samplersd:"+rsmd);
int numberOfColumns = rsmd.getColumnCount();
System.out.println("numberOfColumns:"+numberOfColumns);
while (rs.next()) {
System.out.println("sample1:"+rs);
for (int i = 1; i <= numberOfColumns; i++) {
if (i > 1) System.out.print(", ");
String columnValue = rs.getString(i);
System.out.print(columnValue);
System.out.println("");
st.close();
con.close();
} catch(Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}1: What is the name of the excel sheet?
2: What is printed in this program? null ? anything?
error?Excel file name is "sample.xls" I set excel file connectivity in my JDBC driver(DSN). Here in my program I am not giving that excel file name. I am giving only that excel sheet name. that is followed
ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );The output of this program is given bellow.
sample:sun.jdbc.odbc.JdbcOdbcResultSet@1b67f74
samplersd:sun.jdbc.odbc.JdbcOdbcResultSetMetaData@530daa
numberOfColumns:2 -
How to store the data read from excel using java code in Ms access database
Hi. I wrote a code to read the data from excel. May i know how can i save it to Ms access database using java. Also i have many excels. So i should not connect the database using DSN. So is there any other way to achieve this?
kramish wrote:
Im pretty sure that Access does support JDBCNo it does not. It supports ODBC.
just doing a quick Google came up with some pages:
http://blog.taragana.com/index.php/archive/access-microsoft-access-database-from-java-using-jdbc-odbc-bridge-sample-code/
http://www.javaworld.com/javaworld/javaqa/2000-09/03-qa-0922-access.html
Both articles explains how to use the jdbc-odbc bridge. I think I've seen a pure jdbc driver for access but it wasn't from Microsoft and it wasn't free.
Kaj -
How to convert from xml file to html using java code
How to convert from xml file to html file using java code
Get yourself Apache Xalan or Saxon or some XSLT processor
String styleSheet = "/YourXSLTStylesheet.xsl";
String dataSource = "/YourXMLDocument.xml";
InputStream stylesheetSource = TransformMe.class.getResourceAsStream(styleSheet);
InputStream dataSourceStream = TransformMe.class.getResourceAsStream(dataSource);
OutputStream transformedOut = new FileOutputStream("filename.html");
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheetSource));
transformer.transform(new StreamSource(dataSourceStream), new StreamResult(transformedOut));You'll also need to learn XSLT if you don't already know that. Here's a good place to start
http://www.w3schools.com/xsl/ -
How to add DTD syntax line into XML using java code
Hi,
I am building xml file with java, usiing document.createElement()
and document.appendChild(element),
like that
now i need to add dtd file path and synatx in the top of the xml file,
how can i do it through java code
any body could help me
i appreciate your help.
thanks
DurgaHi Suneetha,
Thanks for your reply..
Now i am getting docType in xml file but not in the format of what i want
please look at my code
i need
<!DOCTYPE myRootElement SYSTEM "myXMLDTD.dtd" >
but i am getting
<!DOCTYPE myRootElement PUBLIC "" "myXMLDTD.dtd">
There is change i need to get the SYSTEM in place of PUBLIC and i need to get rid of "" code between dtd and PUBLIC
for this i am doing in my code as
DocumentType theDocType = new DocumentImpl().createDocumentType ("SYSTEM","","myXMLDTD.dtd");
Document theDoc = new DocumentImpl(theDocType);
i dn't know what is the wrong ? i dn't know what are the parameters at what place to pass if you know any thing just let me know
thanks in advance
and i apperciate you help.
Durga -
How to change the properties of a directory using java code
Hai All,
I need to change the properties of directory( websharing).
Can i do this using java code.
Regards,
CharanI need to change the properties of
directory( websharing).
an i do this using java code.Depends on whether the server has a Java API to do it. Most likely it hasn't. -
How to compare two huge xml files(50MB+) using Java Code
I want to compare two huge xml files using java code and need to find the difference of those xml files
is there any API for thatYou should find third party API
-
How to set proxy authentication using java properties at run time
Hi All,
How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
=> Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
import java.io.*;
import java.net.*;
public class DnldURLWithoutUsingProxy {
public static void main (String[] args) {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
u = new URL("http://www.yahoo.com.au/index.html");
is = u.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
dis.close();
} catch (MalformedURLException mue) {
System.out.println("Ouch - a MalformedURLException happened.");
mue.printStackTrace();
System.exit(1);
} catch (IOException ioe) {
System.out.println("Oops- an IOException happened.");
ioe.printStackTrace();
System.exit(1);
} finally {
try {
is.close();
} catch (IOException ioe) {
}However, it generated the following message when run behind the firewall:
cd C:\Documents and Settings\abc\DnldURL\build\classes
java -cp . DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:320)
at sun.net.www.http.HttpClient.New(HttpClient.java:315)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
I have also tried the command without much luck either:
java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
There is no problem pinging www.yahoo.com from this system.
I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
Java Control Panel - Use browser settings without success.
Thanks,
GeorgeHi All,
How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
=> Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
import java.io.*;
import java.net.*;
public class DnldURLWithoutUsingProxy {
public static void main (String[] args) {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
u = new URL("http://www.yahoo.com.au/index.html");
is = u.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
//Close the input stream
dis.close();
} catch (MalformedURLException mue) {
System.out.println("Ouch - a MalformedURLException happened.");
mue.printStackTrace();
System.exit(1);
} catch (IOException ioe) {
System.out.println("Oops- an IOException happened.");
ioe.printStackTrace();
System.exit(1);
} finally {
try {
is.close();
} catch (IOException ioe) {
}However, it generated the following message when run behind the firewall:
cd C:\Documents and Settings\abc\DnldURL\build\classes
java -cp . DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:320)
at sun.net.www.http.HttpClient.New(HttpClient.java:315)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
I have also tried the command without much luck either:
java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
Oops- an IOException happened.
java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
There is no problem pinging www.yahoo.com from this system.
I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
Java Control Panel - Use browser settings without success.
Thanks,
George -
Very simple question, how do you configure windows 8.1 to use a SD card / external drive as the default install location for software applications? Primarily interested in apps installed from the windows store. This should be available in the settings
charm within the windows store. This must have been overlooked in the development of windows 8.1 or is a bug.
Regards, Bill
* update
I've tried modifying this key and the path:
“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx”
http://answers.microsoft.com/en-us/windows/forum/windows_8-windows_store/how-do-you-install-apps-in-windows-8-from-the/c4fbe2a8-fd3d-41c1-b9a6-6f881eed374f
Also tried using symlinks as detailed here:
http://social.technet.microsoft.com/Forums/windows/en-US/8eee52c2-db0f-4032-8c72-7cd999e8b41a/windows-8-apps-installing-to-secondary-drive?forum=w8itprogeneralHere's some links I've used to try to figure this out:
http://social.technet.microsoft.com/Forums/windows/en-US/2dfc0cd9-7d1b-41de-abce-e03fb6a5a383/metro-apps-not-working-in-windows-8-pro-x64-after-moving-users-and-programdata-folders?forum=w8itproinstall
http://social.technet.microsoft.com/Forums/windows/en-US/8eee52c2-db0f-4032-8c72-7cd999e8b41a/windows-8-apps-installing-to-secondary-drive?forum=w8itprogeneral
http://social.technet.microsoft.com/Forums/windows/de-DE/f5e33ac9-beab-4b99-b3ca-7cb5e6f415e4/how-do-you-change-metro-apps-default-install-location?forum=w8itprogeneral
Regards, Bill
The registry method does not work with 8.1. I found this out the hard way. Doing it on 8.1 will leave you reinstalling the OS if you didn't do a SRP beforehand. -
How can I configuration MBean in weblogic server using the console ?
How can I configuration MBean in weblogic server using the console ?
I hear people talking about mbeans in weblogic server I have look in the console I can not find where , or how to do it.
can some body explain that or a link that explain it, how to do it on the console ?Hi,
Registering Custom MBeans from Admin Console is not yet possible. But yes there are ways to Configure and Utilize Custom MBeans ...
http://weblogic-wonders.com/weblogic/2010/02/16/registering-and-invoking-custommbeans/
Thanks
Jay SenSharma
Maybe you are looking for
-
Flash E-Card Design Contest!
This is EkkoBlue Media Studios, a design studio working with Universities and Design Colleges to bring you a Flash E-Card Design contest. The goal of this contest is to design animated Flash E-Cards. Treat these E-Cards as you would real greetings ca
-
Photoshop CC crash when using Nik Collection
I have been using Lightroom 5 and Nik Collections plugins successfully for a while and just got Photoshop CC. Unfortunately Photoshop CC crash when I save my work that I have done in ColorEfex Pro 4 or SilverEfex Pro 2. The other plugins in the Nik C
-
How Do I Import Music Without iTunes "Organizing" My Library And Hard Drive
Each Time I Add Music to iTunes, It Rearanges My Music By Artist Tags. Both In iTunes And On My Hard Drive. How Can I keep It from Doing This?
-
Need help in getting posts deleted
HI, I was trying to post a query problem whcih has been answered by Hugo earlier, but ran into "Unexpected error" and am unable to delte the post now, or even access it. All post are in t-sql forum. Can you please help delete them. These are the 2 r
-
C4380 Trouble printing wirelessly MAC
Photosmart C3480 My MacAir is not able to print to my C3480 printer. This is a new issue. I've been printing wirelessly since January from this computer. OS 10.9 Message I'm seeing is "The printer is not connected" and in the que under the doc name