Serialization of java.sql.Connection
Hi ,
I just came across a input from my colleague that Connection object once created are not serializable across jvm's
Is it true??
fast yes or no will help my curosity ....giving reason also will be genrousity ...anyway I will test this now
It can't be done.
The reason is that a connection uses a network resource (such as a TCP/IP socket) which uses the network stack on the machine, and eventually the machine's hardware. It is not possible to serialize things like a connected socket, because it's significance is machine-specific, not only in terms of a virtual address (such as an IP address), but also in terms of the way the operating system is using the hardware.
Serialization is only good if what you're serializing is only data.
Rhys
Similar Messages
-
Can't we pass java.sql.Connection as parameter toDatum() method
I am in mid of java 1.3 to 1.4 migration, now I am getting the below error.can't we pass java.sql.Connection as a param to toDatum(), but I did the same before for another module and it worked fine, now I am getting the error.
any changes need to be done?
[b]toDatum(oracle.jdbc.driver.OracleConnection,java.lang.String) in oracle.jpub.runtime.MutableArray cannot be applied to (java.sql.Connection,java.lang.String)
return array.toDatum(c, SQL_NAME);
^
1 error
I changed to use
import oracle.sql.ORAData;
import oracle.sql.ORADataFactory;
instead of
import oracle.sql.CustomDatum;
import oracle.sql.CustomDatumFactory;In general, it's bad practice to be that "open" with regards to parameters to methods, especially when using remote invocations. However, if you really, really, really, really need to - and I doubt you do - you can use Serializable for the type of parameter. But that's still inelegant and, well, raises all sorts of issues, starting with your design...
-
What is the recommended way to get a java.sql.Connection to the DB for ADF
How do I create a standalone database connection based on the datasource setup in ADF?
I have seen code like this in a method of AppModuleImpl.java but that seems a bit of a hack.
Connection conn = this.getDBTransaction().createStatement(0).getConnection();
What I need is a java.sql.Connection to the database used in the application module so I can call PL/SQL code and or work with AQ queues.
I would prefer a separate connection from the one used by the ADF model so it can have its own transaction control etc.
But I would like to get the connection created authenticated based on regular datasource setup.http://www.oracle.com/webfolder/technetwork/jdeveloper/howto/11114/managedserver/wlsadfms.html#8c
https://blogs.oracle.com/jdevotnharvest/entry/accessing_weblogic_jdbc_datasource_from -
Java.sql.Connection x J9 VM
Is possible to use class java.util.Connection with J9 VM using CDC/PP ?
Logging:
java.lang.NoClassDefFoundError: java.sql.Connection
at java.lang.Class.verifyImpl(NativeMethod)
Help me please;
Thanks
[]'sIs possible to use class java.util.Connection with J9 VM using CDC/PP ?Yes. Check your classpath JARs for java.sql.Connection. You may be missing the jar "database_enabler.jar". See:
http://blog.vikdavid.com/2005/08/troubleshooting.html
Vik -
How to check whether java.sql.Connection has been dropped or not
Hi,
How can i check whether the connection is dropped from the database or not by using java.sql.Connection API.
ThanksThere's a few ways to check Connections, each with a different use:
(1) conn.isOpen()
(2) conn == null
(3) the last one is a little more involved and adds some overhead. You can run SELECT 1 FROM dual; (Oracle) or SELECT 1 (MSSQL) and check for exceptions.
The only way to check a connection, as far as I know, is to use it. That said, there must be a better way??? -
BC4J - How can I get java.sql.Connection ?
Hi,
I am using BC4J for my Application and want to get the java.sql.Connection from ApplicationModule or from anywhere such that I can use the same connection as in ApplicaitonModule, to do some work in the database.
I tried to get it from the SessionInfo :
sessioninfo.getConnectionInfo();
but this returns me oracle.dacf.dataset.connections.Connection
How can I convert this to java.sql.Connection?
Or Is there any other means to get hold of sql.Connection?
Any help would be appreciated.
TIAThanks for this reply.. but
I need java.sql.Connection to call a stored procedure in Oracle database and I have to pass oracle.sql.ARRAY to it.
My Stored Procedure looks like:
create or replace PROCEDURE updateRevenueNetworkInfo(revid varchar2, netids Varchar32Array)
where 'Varchar32Array' is my own datatype in the database which is mapped to oracle.sql.ARRAY object in java.
And in order to create oracle.sql.ARRAY I need java.sql.Connection as shown below
oracle.sql.ARRAY pTable = new oracle.sql.ARRAY(desc, connection, netidarray);
I am executing my stored procedure like this:
ArrayDescriptor desc = null; CallableStatement cs = null;
String[] netidarray = {"00-AOL-T1-N003"};
desc = ArrayDescriptor.createDescriptor("VARCHAR32ARRAY", conn);
oracle.sql.ARRAY pTable = new ARRAY(desc, connection, netidarray);
cs = conn.prepareCall( "BEGIN updaterevenuenetworkinfo(?,?); END;" );
((OracleCallableStatement)cs).setString(1,"00-AOL-T1-R3");
((OracleCallableStatement)cs).setArray(2, pTable);
cs.execute();
Is there any way of getting java.sql.Connection such that I can use the same connection as in the ApplicationModule?
OR Is there any other way of passing Array of Strings to a stored procedure in the database?
Thanks for the help.
null -
Need help with a Java-SQL connection
My classmates and I created a DesktopFrame. Within it are reports that require a connection to an MS Access Database. When a report in an InternalFrame is opened: the SQL command works, there is a connection, and everything goes well on the first run.
However, when another InternalFrame is opened or when the same InternalFrame is opened the 2nd time, an error occurs. It produces a java.sql.SQLException: General Error.
Can anyone help me? Thanks in advance.Provide more info, maybe even some code segments. (Not all). May be easier to help
-
Access to java.sql.Connection objects
Hi,
The Kodo JDO developers guide states 2 methods to obtain a Connection
object for the database.
The first method makes use of a function getStoreManager(), which
doesn't seem to exist anywhere and which is certainly not mentioned
anywhere in the documentation.
The second method makes use of a class DataSource, which also does not
exist anywhere. I am aware that this class is present in JDK1.4 but we
are using 1.3 and it states Kodo works on this version.
Can anybody please clarify how I obtain a connection using these two
methods?
LarsOn 7/1/02 9:15 AM, "Lars" <[email protected]> wrote:
Hi,
The Kodo JDO developers guide states 2 methods to obtain a Connection
object for the database.
The first method makes use of a function getStoreManager(), which
doesn't seem to exist anywhere and which is certainly not mentioned
anywhere in the documentation.getStoreManager() is a Kodo-specific method in
com.solarmetric.kodo.runtime.PersistenceManagerImpl. The JavaDoc for this
class is not available in Kodo JDO 2.2.x; it is available in Kodo JDO 2.3.0.
The second method makes use of a class DataSource, which also does not
exist anywhere. I am aware that this class is present in JDK1.4 but we
are using 1.3 and it states Kodo works on this version.DataSource is part of the Java SQL standard extensions, in javax.sql. See
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/sql/DataSource.html for
more documentation on it.
Note that we do not require that you use a JDBC 2.0 driver (one that
supports javax.sql). We provide our own implementation of DataSource that is
used whenever a connection URL is specified. If you want to use your own
connection pooling etc. with a JDBC 1.0 driver, then you will have to
implement the DataSource interface on your own; we assume that the
ConnectionFactory object implements the DataSource interface.
-Patrick
Patrick Linskey [email protected]
SolarMetric Inc. http://www.solarmetric.com -
Oracle, Serializable and java.sql.SQLException
I'm reading in the weblogic documentation about serializable transactions
and Oracle at:
http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_environment.html
I've excerpted below the section of interest. Essentially it says that if
you want to use an isolation level of SERIALIZABLE with Oracle,
you must be prepared to catch and retry transactions which fail due
to the "can't serialize access for this transaction". What I don't understand,
is where do I catch this exception. The doc below suggests that it
is in the EJB client code. By this, I assume it should be caught
by any client calling into an EJB method which is starting a transaction.
What I don't understand is I didn't think that ejb methods threw a
java.sql.SQLException. How can I catch this exception? The
exception is caused at commit time, which I don't have any
direct control over since I am using CMP.
Do I then need to inspect the exception text for the string:
"ORA-08177: can't serialize access for this transaction", in order
to determine whether to retry the transaction?
Is there any sample code for this. I just need to know where
the exception should be caught in my code, and how to
inspect the exception (scanning text based error messages
sounds problematic, since the exact message text might
change over versions of the database and deployment, etc.).
I am planning on using CMP, so I am not making any
jdbc calls directly.
Jason
Special note for Oracle Databases
Keep in mind that Oracle uses optimistic concurrency. As a consequence, even with a setting of TRANSACTION_SERIALIZABLE, Oracle does
not detect serialization problems until commit time. The message returned is:
java.sql.SQLException: ORA-08177: can't serialize access for this transaction
Even if you use the TRANSACTION_SERIALIZABLE setting for an EJB, you may receive exceptions or rollbacks in the EJB client if
contention occurs between clients for the same rows. To avoid these problems, you must ensure that clients catch and examine the SQL
exceptions, and take appropriate action, such as restarting the transaction.
Jason Rosenberg
SquareTrade
(remove 'nospam' from my return address)I'm reading in the weblogic documentation about serializable transactions
and Oracle at:
http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_environment.html
I've excerpted below the section of interest. Essentially it says that if
you want to use an isolation level of SERIALIZABLE with Oracle,
you must be prepared to catch and retry transactions which fail due
to the "can't serialize access for this transaction". What I don't understand,
is where do I catch this exception. The doc below suggests that it
is in the EJB client code. By this, I assume it should be caught
by any client calling into an EJB method which is starting a transaction.
What I don't understand is I didn't think that ejb methods threw a
java.sql.SQLException. How can I catch this exception? The
exception is caused at commit time, which I don't have any
direct control over since I am using CMP.
Do I then need to inspect the exception text for the string:
"ORA-08177: can't serialize access for this transaction", in order
to determine whether to retry the transaction?
Is there any sample code for this. I just need to know where
the exception should be caught in my code, and how to
inspect the exception (scanning text based error messages
sounds problematic, since the exact message text might
change over versions of the database and deployment, etc.).
I am planning on using CMP, so I am not making any
jdbc calls directly.
Jason
Special note for Oracle Databases
Keep in mind that Oracle uses optimistic concurrency. As a consequence, even with a setting of TRANSACTION_SERIALIZABLE, Oracle does
not detect serialization problems until commit time. The message returned is:
java.sql.SQLException: ORA-08177: can't serialize access for this transaction
Even if you use the TRANSACTION_SERIALIZABLE setting for an EJB, you may receive exceptions or rollbacks in the EJB client if
contention occurs between clients for the same rows. To avoid these problems, you must ensure that clients catch and examine the SQL
exceptions, and take appropriate action, such as restarting the transaction.
Jason Rosenberg
SquareTrade
(remove 'nospam' from my return address) -
Java.sql.connection problems
Hi, I hav got this problem:
PRB 1
I have got the JDBC connection established with the OracleDataSource instance on my java application
I wonder if there is a way to check the connection if it is still alive. any hint? i tried connection.isClosed() but that doesn't help.
PRB 2
I am in this scenario:
The connection is established during application start and something goes wrong say like the DB server goes offline in the middle of no where and I do a commit / rollback. I will get a SQLExeption called. But right after the db comes back online.. i tried to do a commit / rollback, the SQLExeption is still persist.
Q1. Does this mean that when the exception is caught, my connection would no longer be valid and I need to restart the application?
Q2. could i reinitialize the connection after the exception to avoid the restart?
Thank you.Hi, I hav got this problem:
PRB 1
I have got the JDBC connection established with the
OracleDataSource instance on my java application
I wonder if there is a way to check the connection if
it is still alive. any hint? i tried
connection.isClosed() but that doesn't help.From Java APIs reg. isClosed():This method is guaranteed to return true only when it is called after the method Connection.close has been called.
This method generally cannot be called to determine whether a connection to a database is valid or invalid. A typical client can determine that a connection is invalid by catching any exceptions that might be thrown when an operation is attempted.
PRB 2
I am in this scenario:
The connection is established during application start
and something goes wrong say like the DB server goes
offline in the middle of no where and I do a commit /
rollback. I will get a SQLExeption called. But right
after the db comes back online.. i tried to do a
commit / rollback, the SQLExeption is still persist.
Q1. Does this mean that when the exception is caught,
my connection would no longer be valid and I need to
restart the application?
Q2. could i reinitialize the connection after the
exception to avoid the restart?Once your DB goes down, your connection is broken. You cannot do anything with that connection...like Rollback, commit etc. You need to re-establish the connection. You don't need to restart the application, but you might want to check if the connection is null. If it is, you might have to try a new connection. Probably, your application can quit trying for a connection after 'x' number of attempts.
Kumar -
Java.sql.Connection charset property
Hello!
AFAIK, usual way to establish JDBC connection to DB using 1-byte encoding
was:
props.put("user",user);
props.put("password",password);
props.put("charSet",encoding);
Connection con = DriverManager.getConnection(url,props);
How to do the same with JDO PersistenceManagerFactory?
Does Kodo have appropriate optional property?Note that in the mean time, it is possible to work around this issue by
supplying a DataSource object to our PersistenceManagerFactory.
-Fred
Viktor S. Grishchenko <[email protected]> wrote:
Hello!
AFAIK, usual way to establish JDBC connection to DB using 1-byte encoding
was:
props.put("user",user);
props.put("password",password);
props.put("charSet",encoding);
Connection con = DriverManager.getConnection(url,props);
How to do the same with JDO PersistenceManagerFactory?
Does Kodo have appropriate optional property?--
Fred Lucas
SolarMetric Inc.
202-595-2064 x1122
http://www.solarmetric.com -
Exception in method createStatement() of java.sql.Connection
Hi,
When creating a statement :
Statement stat = conn.createStatement();
I got this error:
java.lang.NegativeArraySizeExceptionoracle.net.ano.CryptoDataPacket.decryptAndChecksum(CryptoDataPacket)
oracle.net.ano.CryptoDataPacket.<init>(CryptoDataPacket)
oracle.net.ano.AnoNetInputStream.processPacket(AnoNetInputStream)
oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:728)
oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:700)
oracle.jdbc.ttc7.Oopen.receive(Oopen.java:103)
oracle.jdbc.ttc7.TTC7Protocol.open(TTC7Protocol.java:497)
oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:505)
oracle.jdbc.driver.OracleConnection.privateCreateStatement(OracleConnection.java:693)
oracle.jdbc.driver.OracleConnection.createStatement(OracleConnection.java:570)
Any idea of what is the problem?
Thanks in advance,
KarimHi,
I am trying to open service browser in Test tools to test entity service.But Service browser is not opening and i am getting 'access forbidden'.Can you please help to resolve this issue.And what role i have to add for CAF user/developer.
Thanks,
Murthy. -
Java.sql.SQLException: Closed Connection error when invoking web service
Hi
I've assembled a simple web service for an Oracle PL/SQL package and deployed it on a Standalone OC4J, when I come to invoke it on the Oracle Enterprise Manager screen I'm getting the following returned within the envelope body:
<env:Body>
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>Internal Server Error (serialization error: java.sql.SQLException: java.sql.SQLException: Closed Connection)</faultstring>
</env:Fault>
</env:Body>
The function that is called within the database returns a user defined object that consists of a RAW value and an XMLTYPE. The function takes a string as a parameter, when I enter a string that I know will not return an object there is no error in the envelope body, only when there is an object to return does the error appear.
Anyone have any suggestion as to why this is?I'm no further forward with this: has anyone assembled, deployed and invoked a web service that returns a XMLTYPE?? I know this should be possible but I think there's maybe some manual intervention required with the classes created with webservicesassembler: I'd really appreciate it if anyone with any experience of this kind of thing could help me think this through.
-
Connection error using import java.sql.*;
I have a very strange error. See the code below:
import java.sql.*;
import java.lang.*;
class a7 {
public static void main(String args[]) {
String kolom,ko = new String();
String db = "devarbn1";
String url = "jdbc:odbc:"+db;
String login = "arbor";
String password = "arbor123";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String BasisQuery = "select COLUMN_NAME " +
" from all_tab_columns " +
" where table_name = ? ";
System.out.println("Database: " + db);
Connection con;
try {
Class.forName(driver);
} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try {
con = DriverManager.getConnection(url,login,password); //this line gives an error!!!
and so on.....
This is a fragment of the whole program. All of a sudden I cannot compile it anymore using jdk1.3 or jdk 1.4 (I never had compiling problems before with this program)
It gives the following error message: incompatible types, found Connection.
I haven't got a clue what went wrong. I have a lot of other java files in which a connection is involved. I cannot compile any of them anymore. Even reinstalling jdk1.4 or 1.3 doesn't help. Can anyone please help me?
Thanx, debeumersYes, the whole message is:
incompatible types found : java.sql.Connection required : Connection.
The whole code is (it is from a different java file then the code I used before)
import javax.sql.*;
import java.sql.*;
import java.lang.*;
public class Connection {
static final String arb_nl = "arbornl";
static final String arb_fr = "arborfr";
static final String clar_nl = "clarnl";
static final String clar_fr = "clarfr";
static final String po = "pcnlpp";
static final String user_clar_nl = "report";
static final String pass_clar_nl = " r3p0rt";
static final String user_clar_fr = "report";
static final String pass_clar_fr = " r3p0rt";
static final String user_arb_fr = "report";
static final String pass_arb_fr = " r3p0rt";
static final String user_arb_nl = "report";
static final String pass_arb_nl = " r3p0rt";
static final String user_po_nl = "report";
static final String pass_po_nl = "r3p0rt";
static boolean a = true;
static boolean b = true;
static boolean c = true;
static Connection conarb,conclar,conpo;
static String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String loginarb = user_arb_nl;
String passwordarb = pass_arb_nl;
String loginclar = user_clar_nl;
String loginpo = user_po_nl;
String passwordpo = pass_po_nl;
String passwordclar = pass_clar_nl;
public Connection() {
public void makeConnection(String database,String user,String password,String type) {
String url = "jdbc:odbc:" + database;
try {
Class.forName(driver);
} catch (java.lang.ClassNotFoundException ex) {
System.err.print("ClassNotFoundException: ");
System.err.println(ex.getMessage());
a = false;
try { if (type=="ARB") { conarb = DriverManager.getConnection(url,user,password);} //giving the problem!!
if (type=="CLAR") { conclar = DriverManager.getConnection(url,user,password);} //giving the problem!!
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
b = false;
/* try { if (type=="PO") {conpo = DriverManager.getConnection(url,user,password);}
} catch(SQLException ex) {System.err.println("SQLException: " + ex.getMessage()); c = false;}*/
I hope you can help..
Thanks...debeumers -
I keep getting the following error when I try to use 2 different java.sql.Connections
from 2 different database connection pools in my message ejb. The message ejb
uses container managed transaction. The 2 connection pools point to different
Sybase Servers.
Any help will be much appreciated !!!
java.sql.SQLException: Connection has already been created in this tx context
for pool named adrxSYBDEV07. Illegal attempt to create connection from another
pool: Sybbev07Pool JDBCUtil > getConnection()Hi Eddie,
"Eddie Baue" <[email protected]> wrote in message
news:3ddbf74f$[email protected]..
I keep getting the following error when I try to use 2 differentjava.sql.Connections
from 2 different database connection pools in my message ejb. The messageejb
uses container managed transaction. The 2 connection pools point todifferent
Sybase Servers.In order to access more then one database base within
a TX you need to have TXDataSources backed by XA
connection pools...
Regards,
Slava Imeshev
Maybe you are looking for
-
Macbook Airport doesn't work on AC power
Yeah, that's basically the deal. My airport decides that when it's connected to the charger, it randomly drops out (ie the signal thing greys out). If I click back on it, the network has disappeared and I can't get back on unless I unplug the charger
-
HELP: Unintentional audio keyframing
Hi, I'm not sure how else to describe the problem aside from unintentional audio keyframing, but not that is visible in any individual audio tracks. Here's what's happening. I have a single video clip of someone entering a car. when he's in the car
-
Objects (leafs) in Objects (Nodes) in JTree ?
i have Vector a from (Class 1)Objects, each includes Vector b from (Class 2)Objects. when i pass the Vector a to the JTree i see the (Class 1)Objects as Leafs. but i want to see them as Nodes and the (Class 2)Objects as children for the Nodes. how to
-
Dynamic query to drop apps schema
Hi, We are having a test ERP instance and we are refreshing it with ERP PROD export data through import on ERP test instance. Now we want to drop all Oracle apps schema only in our test instance and through Import they will get created again. Is ther
-
How to block face book or orkut or any other websites
i want to block certains websites, which are harmful for children. Kindlhy inform how is it possible