Jdbc Statement hangs
Folks ,
I have writen some jdbc code and my applications hangs intermittently, we are using oracle database .
Thanks,
Manish
Hi,
What do you mean by "applications hangs intermittently"?
But try to put following logic to figure out what is the time taken by jdbc sql query.
a) get system time before the execution of sql query and store it in temp variable t1
b) get system time after the execution of sql query and store it in temp variable t2
c) Find out the difference and print it
Once you are confident that SQL query is the one taking longer than expected time, check with Oracle experts in your org. for analyzing the log for the query and reasons for taking so much time
regards,
ganga
Similar Messages
-
How to insert an image file as blob using JDBC Statement
Hi,
I'm new on java.
I want the code to insert an image file in Oracle database whose data type is blob.
i want to use JDBC statement not the prepared statement.
Please help me out.user8739226 wrote:
thanks for the solution.
I want to ask one thing
let say i've created a method in a bean in which i'm passing three parameters.
One is tablename as String, Second is Name of tablefields as Object, Third is Values as Object
Like:
public synchronized int insert(String table,Object[] fields, Object[] values)Ah now we're getting somewhere. I was trying to come up with a situation where using a regular Statement over PreparedStatement would be viable and came up with practically nothing.
In the method body i'm accessing the table fields and values and combining them into the insert sql query.
how can i do this using preparedstatment.
how do i come to know here in this bean that this value is int or string or date at runtime to use setInt, setString, setdate or setBlob respectively.That's your problem. Bad design. You want to make some sort of universal insert method that can insert anything anywhere. But it doesn't really make sense, because whenever you're trying to insert something, you know exactly what you want to insert and where. You could use a PreparedStatement at that point (although encapsulate it in its own method). Now you're trying to create your own poorly designed framework over JDBC that doesn't solve problems, only increases them.
Above was the only reason i saw, i was using statement instead of preparedstatment as statement was looking easy in this situation.
please, give me the solution of above using preparedstatment.No, rather you should reconsider your design. What advantage does your insert() method give you over, let's say using a regular PreparedStatement. Granted, you can put your connection opening and other boilerplate code in the method. But if that's your only problem, then your insert method isn't gonna be much use. You could always switch to JPA for example and work with that. -
How to get the jdbc statement profile in 8.1
the wls 8.1 api does not have the methods in the wls 7 api for jdbc statement profiling...
in 7, the connection pool mbean has
setSqlStmtProfilingEnabled()
and the connection pool runtime mbean has
getStatementProfiles(int index, int count)
but in 8, i don't see these. i see the JDBCStatementProfile object in the api, but i don't see how to enable it or retrieve it.
is this feature removed? or moved?
thanksThanks for your response. But I need Process ID
not Product ID.
GetCurrentProcessID
Function should return you Process ID.
Gaurav Khanna | Microsoft .NET MVP | Microsoft Community Contributor -
Hi,
I have turned on JDBC Statement Profiling on my server. I can
get the statements being executed, but the Start & Stop times or
all Statements is the same. The relevant code and output follows.
Anybody see what I am doing wrong.
thanks,
Harish.
public static void printJDBCStatement(JDBCStatementProfile mb) {
System.out.println("\tStatement: " + mb.getStatementText());
System.out.println("\t\ttime = " + mb.getTimeTaken());
System.out.println("\t\tstarttime = " + mb.getStartTime());
System.out.println("\t\tendtime = " + mb.getStopTime());
System.out.println("\t\tthread = " + mb.getThreadId());
System.out.println("\t\tParams:");
int cnt = mb.getParameterCount();
for(int i=0; i<cnt;i++) {
System.out.println("\t\t\tParam " + (i+1) + mb.getParameter(i+1));
Statements:
Statement: INSERT INTO QUERY (ID, TYPE, OWNER, OBJVERSION) VALUES (?, ?, ?,
0)
time = 0
starttime = 1033591935157
endtime = 1033591935157
thread = Thread-15
Params:
Param 132397
Param 212650
Param 399999999
Statement: SELECT OBJVERSION FROM QUERY WHERE ID = ? FOR UPDATE NOWAIT
time = 0
starttime = 1033591935167
endtime = 1033591935167
thread = Thread-15
Params:
Param 132397
Statement: DELETE FROM SELECT_LIST WHERE QUERY_ID = ?
time = 0
starttime = 1033591935177
endtime = 1033591935177
thread = Thread-15
Params:
Param 132397
Statement: SELECT 5, OBJVERSION, 0 FROM QUERY WHERE ID = ?
time = 0
starttime = 1033591935187
endtime = 1033591935187
thread = Thread-15
Params:
Param 132397"Harish" <[email protected]> wrote in message
news:[email protected]..
>
I know for a fact that the statements take more than a 1ms.Could you try to run this code and tell what it prints?
public class test {
public static void main(String args[]) throws Throwable {
long previousTime = 0;
long currentTime = 0;
for (int i = 1; i < 1000000; i++) {
previousTime = System.currentTimeMillis();
// Thread.sleep(20);
currentTime = System.currentTimeMillis();
if (currentTime != previousTime) {
System.out.println("Difference: " + (currentTime - previousTime));
Regards,
SlavaImeshev
>
thanks,
Harish.
"Slava Imeshev" <[email protected]> wrote:
Hi Harish,
AFAIR this fact means that execution time is
less than 1ms. It's because java timer is not
very good at measuring precise periods of time.
So these digits are pretty good :)
Regards,
Slava Imeshev
"Harish" <[email protected]> wrote in message
news:3d9b6cfd$[email protected]..
Hi,
I have turned on JDBC Statement Profiling on my server. I can
get the statements being executed, but the Start & Stop times or
all Statements is the same. The relevant code and output follows.
Anybody see what I am doing wrong.
thanks,
Harish.
public static void printJDBCStatement(JDBCStatementProfile mb){>
Statements:
Statement: INSERT INTO QUERY (ID, TYPE, OWNER, OBJVERSION) VALUES
0)
time = 0
starttime = 1033591935157
endtime = 1033591935157
thread = Thread-15
Params:
Param 132397
Param 212650
Param 399999999
Statement: SELECT OBJVERSION FROM QUERY WHERE ID = ? FOR UPDATE NOWAIT
time = 0
starttime = 1033591935167
endtime = 1033591935167
thread = Thread-15
Params:
Param 132397
Statement: DELETE FROM SELECT_LIST WHERE QUERY_ID = ?
time = 0
starttime = 1033591935177
endtime = 1033591935177
thread = Thread-15
Params:
Param 132397
Statement: SELECT 5, OBJVERSION, 0 FROM QUERY WHERE ID = ?
time = 0
starttime = 1033591935187
endtime = 1033591935187
thread = Thread-15
Params:
Param 132397 -
Dear all
I am using oracle 9i(9.2.0.1.0). I have a Merge statement which inserts 14million records.
I am able to execute the merge statement in 4mins.
When i try to execute the same merge on oracle (9.2.0.6 ) with same hardware config on client machine, My merge statement hangs.
Please let me know if any patches are there and what all parameters do i need to look into to trace the problem.
Regards
SurendraHi
Do you have the same indexes and statistics in the two systems?
Ott Karesz
http://www.trendo-kft.hu -
Create procedure statement Hangs in 11g database, doesn't hang in 10.2
I have installed 11g on a windows workstation and created a new database. I then attempted to import a schema from a tried and tested 10.2 database, this hung.
I pinpointed the cause of the hang to a create procedure sstatement within the import file.
I removed the procedure from the 10.2 database, re-exported and imported sucessfully in to the 11g database minus the rogue prrocedure.
I now have a create statement for the procedure thats causing the hangs, and this hangs when I try and run it - it runs fine against my 10.2 database?
I can comment large chunks of the create procedure statment out so I get an anonymous block that runs, and pinpoint the hang down to the inclusion of the the line marked below
(starting FOR UPDATE OF...........).
I cant work out whats going on, I'm no programmer by the way!
Any pointers would be greatly appreciated.
Nick
declare
job_rec job_table%ROWTYPE;
err_msg varchar2(2000);
abort_msg varchar2(2000);
l_ok boolean := TRUE;
l_bat_job varchar2(14) := 's2_novate_RIC';
LINES DELETED FOR PURPOSE OF POSTING CURSOR c_sah IS
SELECT
sah_next,
sah_table_key,
sah_old_status,
sah_new_status,
sah_processed_ind,
sah_processed_date,
sah_processed_time
FROM senatordba.sah_status_audit_history
JOIN (SELECT distinct to_char(spd_next) spd_next
FROM senatordba.spd_std_risk_dets
JOIN senatordba.rso_risk_system_options
ON rso_spd_next = spd_next
AND spd_ric_code = l_ric_code
AND coalesce(l_uw_year, spd_yr) = spd_yr
AND coalesce(l_risk_ref, spd_ref) = spd_ref
ON spd_next = sah_table_key
AND sah_table_code = 'SPD'
AND sah_status_table_code = 'NOV'
AND sah_processed_ind = 'N';
FOR UPDATE OF sah_processed_ind, sah_processed_date, sah_processed_time; <---------if this line is commented out runs OK, if left in, it hangs??
r_sah c_sah%ROWTYPE;
begin
open c_sah;
close c_sah;
end;Hi Nick, no one else has answered so I thought I'd answer my own question, it appears that I was hitting Oracle bug 9294110. had to uninstall 11.2 and install 11.0.7 instead. very annoyed that I wasted ages diagnosing this known problem. The following test should replicate the hang
connect / as sysdba
create user test identified by test default tablespace users temporary tablespace temp;
grant connect, resource to test;
connect test/test
create table a_tab
( col001 number, col002 number, col003 number, col004 number);
create table b_tab( col001 number);
-- the next statement hangs forever
select
a.col002,
a.col003,
a.col004
from
a_tab a
left outer join b_tab
on a.col001 = b_tab.col001
for update of a.col002,
a.col003,
a.col004; -
SELECT statements hang (e.g., SELECT * FROM <table>). My connection is fine but when I attempt to execute a SQL statement (F9) it hangs; the progress bar just goes back and forth with no error reported.
Any ideas???P.S. I get the following error when selecting a database connection from Tools >> SQL Worksheet:
java.lang.NoClassDefFoundError: oracle/bali/xml/dom/buffer/util/EncodingUtils
at oracle.jdeveloper.model.JavaEditionAddin$2.recognize(JavaEditionAddin.java:356)
at oracle.ide.model.NodeFactory.findOrCreateUsingDefault(NodeFactory.java:159)
at oracle.ide.model.NodeFactory.findOrCreate(NodeFactory.java:89)
at oracle.ide.editor.RecentFile.getNode(RecentFile.java:168)
at oracle.ide.editor.RecentFile._getNode(RecentFile.java:217)
at oracle.ide.editor.RecentFile.getContext(RecentFile.java:46)
at oracle.ideimpl.editor.RecentFilesLRU.removeOldest(RecentFilesLRU.java:94)
at oracle.ideimpl.editor.RecentFilesLRU.adjustSize(RecentFilesLRU.java:76)
at oracle.ideimpl.editor.RecentFilesLRU.raiseContextInLRUList(RecentFilesLRU.java:157)
at oracle.ideimpl.editor.EditorManagerImpl.raiseContextInLRUList(EditorManagerImpl.java:1705)
at oracle.ideimpl.editor.TabGroup.setCurrentTabGroupState(TabGroup.java:1316)
at oracle.ideimpl.editor.TabGroup.activateEditor(TabGroup.java:639)
at oracle.ideimpl.editor.EditorManagerImpl.createEditor(EditorManagerImpl.java:1292)
at oracle.ideimpl.editor.EditorManagerImpl.createEditor(EditorManagerImpl.java:1215)
at oracle.ideimpl.editor.EditorManagerImpl.openEditor(EditorManagerImpl.java:1150)
at oracle.dbtools.sqlworksheet.sqlview.SqlEditorWizard.invoke(SqlEditorWizard.java:128)
at oracle.ide.wizard.WizardManager.invokeWizard(WizardManager.java:310)
at oracle.dbtools.sqlworksheet.sqlview.SqlEditorAddin$1.actionPerformed(SqlEditorAddin.java:151)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Right-clicking on a database connection (or double-clicking) connects fine without error. -
What is the size limitation of Oracle JDBC Statement?
Want to know how large is the limiation of one complete SQL insert string can be place
into a JDBC Statement and can insert the big record successfully. I tried up to 13K, JDBC still can accept it. Does some experienced
guru can tell me what is the size limitation
for insert or update SQL string JDBC can accept it?
Thanks a lot.None known. More than 10 GB. Please note Acrobat is not for server use (I mention that because you mention C# and experience shows it is often preferred for backend development).
-
Batching disparate JDBC statements
I am trying to batch execute a bunch of JDBC statements which are disparate - ie. insert , update. Is there a way to do this via Oracle's Thin JDBC driver? Someone mentioned that it might be possible using Oracle JDBC Callable statement interface to bunch together a bunch of SQL statements(not stored procedures) - but i could not find any information on this.
ThanksSeems like you are making it harder than it needs to be. What is wrong with JDBC batching or even Oracle Style batching?
PreparedStatement psIns = con.prepareStatement( <some insert statement> );
PreparedStatemetn psUpd = con.prepareStatement( <some update statement> );
for ( int at = 0; at < numRecsToInserAndUpdate; ++at )
psIns.setLong( 1, uids[at] );
psIns.setBlah( 2, ... );
psIns.addBatch();
psUpd.setString( 1, updateStrings[at] );
psUpd.addBatch();
psIns.executeBatch();
psUpd.executeBatch();The above example uses JDBC style batching, you can as easily do this with Oracle style batching.
R. -
I'm using the connection pooling system from Jakarta commons. My database access works fine most of the time, but for some reason sometimes the database hangs. I will try to access the web-app and the login screen will come up fine, but when I try to log in the app will just sit there trying to access the database forever, and from that point on no database access will work. Here is the code I use to get the connections and access the database. Is there anything I am doing wrong that could be causing this?
import java.sql.DriverManager;
import java.sql.Connection;
import javax.sql.DataSource;
import java.io.PrintWriter;
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.PoolingDataSource;
import org.apache.commons.dbcp.PoolableConnectionFactory;
import org.apache.commons.dbcp.DriverManagerConnectionFactory;
public class ConnectionManager {
private static final ConnectionManager INSTANCE = new ConnectionManager();
//Name of SQL Driver to load
private static final String DRIVERNAME = "com.mysql.jdbc.Driver";
private static final String CONNECTSTRING = "jdbc:mysql:///mysite:admin:mypasswd?autoReconnect=true";
//The actual pool of Database Connections
private static DataSource dataSource;
private static ObjectPool connectionPool;
// Private constructor supresses
// default public constructor
private ConnectionManager( ) {
// Load the Database SQL Driver
try{
Class.forName(DRIVERNAME);
} catch (java.lang.ClassNotFoundException e) {System.out.println ("Database SQL Driver not found!");}
try {
// First, we'll need a ObjectPool that serves as the
// actual pool of connections.
// We'll use a GenericObjectPool instance, although
// any ObjectPool implementation will suffice.
connectionPool = new GenericObjectPool(null);
// Next, we'll create a ConnectionFactory that the
// pool will use to create Connections.
// We'll use the DriverManagerConnectionFactory,
// using the connect string passed in the command line
// arguments.
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(CONNECTSTRING,null);
// Now we'll create the PoolableConnectionFactory, which wraps
// the "real" Connections created by the ConnectionFactory with
// the classes that implement the pooling functionality.
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
// Finally, we create the PoolingDriver itself,
// passing in the object pool we created.
// We then save the datasource object to the class for later use in getting connections
dataSource = new PoolingDataSource(connectionPool);
//System.out.println("Idle: " + connectionPool.getNumIdle() + " - Active: " + connectionPool.getNumActive());
} catch (Exception e){}
//Returns and Instance of the ConnectionManager object (not really necessary)
public static ConnectionManager getInstance( ) {
return INSTANCE;
//Returns a database connection object
public static Connection getConnection(){
Connection conn = null;
try{
conn = dataSource.getConnection();
} catch(java.sql.SQLException e){
System.err.print (e.getStackTrace());
//System.out.println("Idle: " + connectionPool.getNumIdle() + " - Active: " + connectionPool.getNumActive());
return conn;
And here is my database code:
import java.sql.*;
import com.mysite.ConnectionManager;
import java.util.HashMap;
import java.util.Iterator;
Manages a database after getting a database connection from a {@url ConnectionManager} object.
Can do queries and database updates, as well open and close connections.
public class DatabaseManager {
private Connection con = null;
private Statement st;
private ResultSet rs;
//The Structure of the Table, used for query operations
private String[] tableStruct;
Constructor
public DatabaseManager(){
Retrieves a database connection from a {@url ConnectionManager} object.
@param
@return
@see
public void connect(){
con = ConnectionManager.getConnection();
Identifies whether this database connection is still open
@param
@return
@see
public boolean isClosed() throws java.sql.SQLException{
return con.isClosed();
Execute a query on a database connection and get the resultset for that query
@param queryString A String representing the database query
@return The results of the query to the database
@see Statement, ResultSet
public ResultSet query(String queryString) throws java.sql.SQLException{
if (con != null){
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
st.executeQuery (queryString);
rs = st.getResultSet();
return rs;
else {
throw new java.sql.SQLException ("Error has occurred in Datamanager, no Database Connection has been Established.");
Returns the Number of Rows the last query has executed.
@return Number of Rows
public int getRows() throws java.sql.SQLException{
int count = 0;
if (rs != null){
//get the current row number in case were in the middle of a read and want the size
int rowNumber = rs.getRow();
rs.beforeFirst();
while (rs.next()){
count = count + 1;
if (rowNumber == 0){
rs.beforeFirst();
else {
rs.absolute(rowNumber);
return count;
else {
return 0;
Does a record in a particular table exist.
@param tableName name of Table to look in
@param idName Name if Table ID
@param id value of ID
@return True if record exists
@see
public boolean doesExist(String tableName, String idName, String id) throws java.sql.SQLException{
query ("SELECT " + idName + " FROM " + tableName + " WHERE " + idName + "='" + id + "';");
if (getRows() == 1){
return true;
else {
return false;
Update a line (or multiple lines) in the database.
@param updateString The Update Query String to use to update the database
@return
public int update(String updateString) throws SQLException{
int j = 0;
try {
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
j = st.executeUpdate (updateString);
catch (SQLException e) {
throw new SQLException (updateString);
st.close();
return j;
Update a line in the database.
@param tableName Name of table to update the line
@param items The data to be updated in the table
@return
public int update(String tableName, HashMap items, String idname) throws SQLException{
// UPDATE <tablename> SET name1="value1", name2="value2" WHERE id="idvalue"
String updateString;
Iterator keys = items.keySet().iterator();
Iterator values = items.values().iterator();
String optionsString = "";
//Combine the keys into Strings with ,'s separating.
while (keys.hasNext()){
optionsString = optionsString + (String)keys.next() + "=\"" + (String)values.next() + "\",";
//Chop off the last , in the Strings
optionsString = optionsString.substring (0, optionsString.length()-1);
updateString = "UPDATE " + tableName + " SET " + optionsString + " WHERE " + idname + "=" + items.get(idname) + ";";
return insert (updateString);
Delete a Record or Records from the database
@param table Name of the Table to delete data from
@param whereClause what to delete from the table
@see
public void delete(String table, String whereClause) throws SQLException{
String deleteString;
deleteString = "DELETE FROM " + table;
if (whereClause != null) {
if (!whereClause.equals("")){
deleteString += (" WHERE " + whereClause);
deleteString += ";";
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
st.execute (deleteString);
st.close();
Inserts a line of data into a database connection under a given table
@param insertString String Containing the query to send with the Insert Data
@return Number of Rows Affected
public int insert(String insertString) throws SQLException{
int j = 0;
try {
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
j = st.executeUpdate (insertString);
catch (SQLException e){
throw new SQLException (insertString);
st.close();
return j;
Inserts a line of data into a database connection under a given table
@param tableName Name of table to update the line
@param items The data to be updated in the table
@return Number of Rows Affected
public int insert(String tableName, HashMap items) throws SQLException{
// REPLACE INTO <tablename> (itemname1, itemname2) VALUES ("value1", "value2");
String insertString;
Iterator keys = items.keySet().iterator();
Iterator values = items.values().iterator();
String keysString = "";
String valuesString = "";
//Combine the keys into Strings with ,'s separating.
while (keys.hasNext()){
keysString = keysString + (String)keys.next() + ",";
valuesString = valuesString + "\"" + (String)values.next() + "\",";
//Chop off the last , in the Strings
keysString = keysString.substring (0, keysString.length()-1);
valuesString = valuesString.substring (0, valuesString.length()-1);
insertString = "REPLACE INTO " + tableName + " (" + keysString + ") VALUES (" + valuesString + ");";
return insert (insertString);
Sets the table structure for subsequent operations.
@param An array of names that represent a table in a database.
@return
@see
public void setStructure(String[] struc){
tableStruct = struc;
Flushes the Statement and ResultSet object
in case any resources are being used when they
shouldn't be.
public void flushSources() throws java.sql.SQLException{
if (rs != null){
rs.close();
rs = null;
if (st != null){
st.close();
st = null;
Kills the database connection in this object
public void close() throws java.sql.SQLException{
flushSources();
if (con != null){
con.close();
con = null;
}How do I do that, it doesn't even report an error. I could try sticking log traces all over the place, but it may not tell me anything about why the problem is happening.
-
Why my JDBC UPdate hangs up??
Hi, Sir::
I use following simple JDBC Update program to update my table TEST,
See following code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
// create table test(Test_ID number, Test_Val varchar(30));
public class Update {
public static void main(String args[]) {
Connection con = null;
if (args.length != 2) {
System.out.println("Syntax: <java UpdateApp [number] [string]>");
return;
try {
String driver = "oracle.jdbc.driver.OracleDriver";
Class.forName(driver).newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:usa";
con = DriverManager.getConnection(url, "scott", "tiger");
Statement s = con.createStatement();
String test_id = args[0];
String test_val = args[1];
int update_count = s.executeUpdate("INSERT INTO test (test_id, test_val) "
+ "VALUES(" + test_id + ", '" + test_val + "')");
s.executeUpdate("UPDATE test SET TEST_VAL= 'John Alan' WHERE TEST_ID=1");
System.out.println(update_count + " rows inserted.");
s.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
When I run with command:
C:\temp\javaCode>java Update 2 MyTest
It hangs here and did not process, If I remove the statement:
s.executeUpdate("UPDATE test SET TEST_VAL= 'John Alan' WHERE TEST_ID=1");
it works and insert 1 record into Test Table.
What is wrong here??
How to fix it??
Thanks
SunnyDid you try with another Statement? I would try closing the first statement and creating a new one.
Class.forName(driver).newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:usa";
con = DriverManager.getConnection(url, "scott", "tiger");
Statement s = con.createStatement();
String test_id = args[0];
String test_val = args[1];
int update_count = s.executeUpdate("INSERT INTO test (test_id, test_val) "
+ "VALUES(" + test_id + ", '" + test_val + "')");
// close it and create a new one
s.close();
s = con.createStatement();
s.executeUpdate("UPDATE test SET TEST_VAL= 'John Alan' WHERE TEST_ID=1");
Let me know if it works. -
I have a very weird case when a particular JDBC query kills weblogic server. Attached
is a thread dump. What's weird is:
1. There is only one client on the system, and I sware the client sends only one
request. At the same time there are 12 threads trying to execute the same query.
2. The query is at the start of thread dump and it takes ~9sec to execute on our
DB from SQL+. It returns ~300 records. If I change parameters it will be executed
fine. Each time a client wants to execute a query before it is executed it is
dumped to log, and there is only one query per all threads in the dump.
3. Looking into DB log there is no sight of the query that is dumped into log
file. DB does not have a clue... Both DB and WLS are waiting for each other...
Environment:
6.1sp2 on solaris
Oracle 8.1.7
JDBC driver from Oracle 9i
[x.txt]There were two problems: request got hanging in the database (original) with proxy
timing out and making situation worse (sending more requests). 9.2.0.1 did not
have the original problem (statement did not hang), but the price was too high
(data corruption) :( Also the problem was very touchy - we got only two environments
which were duplicating it. This last mail was more on the whining side - hope
that someone seen something similar and can say a-ha! So I guess I'm back in slow
and painful try to reproduce and then fix mode... Most likely it all will end
up with SQL tuning, not app level solution...
"Slava Imeshev" <[email protected]> wrote:
Mike,
AFAIR the poblem was not in the driver but in the load balancer
resubmitting requests. Could you please try to use 9.0.1 driver.
Regards,
Slava Imeshev
"mike" <[email protected]> wrote in message
news:[email protected]...
Unfortunately the story is not completely over.
We found that the new driver in some cases garbles the data. That happenson updates
when WLS is changing object and the first parameter in the updatestatement is
string. Sounds weird, so here more details:
- We found that some strings in the database are garbled.
- JDBC trace brought us to update statements. It looks like for eachupdate container
creates prepared statement and sets parameters on it.
- If the first parameter is a string then it will be garbled (happenswith
two
independant objects).
The problem is defenitely driver-specific. It does not show up withany
driver
but 9.2.0.1. All previous drivers work right, but 9.0.1 that we usedbefore had
the problem described in the thread, and 8.x work at least 10 timesslower
(no
kidding).
Test app which connects to the same oracle instance and executes thestatement
from JDBC log works fine (sure it does). Adding nls_charset to classpathdoes
not make any difference. Attempt to create statement from within WLSwas
not taken.
Solution was even more bizzare. Since it was happening only when thefirst
attribute
was string we shuffled attributes and the problem went away. But Ido not
believe
that is a solution - IMHO that just masks the problem.
Any and all brignt and not-so-much ideas are welcome. -
JDBC query hangs for 60 seconds
Hi,
I'm trying to perform a series of very simple queries on a 8.1.7 database with jdk1.4 and ojdbc14 drivers. Every now and then, a query just hangs for exactly 60 seconds before continuing, without throwing any kind of exception. This sometimes happens after a couple of hundred queries, but it can also be after 4 or five. I thought maybe the database runs out of cursors, but then I would get an exception right? After every query, I close the ResultSet and Statement, so it should work just fine. When I tested the same program on PostgreSQL 7.2, it worked perfectly. Is this a problem with the Oracle JDBC drivers, or am I missing something?
Here's the code of my simple test app:
import java.sql.*;
import java.io.*;
class JdbcTest {
public static void main (String args []) throws Exception {
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@foo.bar.com:1521:BLABLA","test", "test");
for (int i=0;i<500;i++) {
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT sitenr,omschrijving FROM site");
while (rset.next ())
System.out.println (rset.getString (1) + ": " + rset.getString(2));
rset.close();
stmt.close();
conn.close();
}Here's the thread dump:
"Signal Dispatcher" daemon prio=10 tid=0x009E8118 nid=0xdc4 waiting on condition
[0..0]
"Finalizer" daemon prio=9 tid=0x0003E6F0 nid=0xdd4 in Object.wait() [ab1f000..ab
1fd88]
at java.lang.Object.wait(Native Method)
- waiting on <02F81698> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
- locked <02F81698> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
"Reference Handler" daemon prio=10 tid=0x0003D2C0 nid=0xdd8 in Object.wait() [aa
df000..aadfd88]
at java.lang.Object.wait(Native Method)
- waiting on <02F81700> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:426)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:113)
- locked <02F81700> (a java.lang.ref.Reference$Lock)
"main" prio=5 tid=0x00034AB8 nid=0xdc8 runnable [7f000..7fc3c]
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at oracle.net.ns.Packet.receive(Unknown Source)
at oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
at oracle.net.ns.NetInputStream.read(Unknown Source)
at oracle.net.ns.NetInputStream.read(Unknown Source)
at oracle.net.ns.NetInputStream.read(Unknown Source)
at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:931)
at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)
at oracle.jdbc.ttc7.Oopen.receive(Oopen.java:105)
at oracle.jdbc.ttc7.TTC7Protocol.open(TTC7Protocol.java:586)
- locked <02FCA940> (a oracle.jdbc.ttc7.TTC7Protocol)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:385)
at oracle.jdbc.driver.OracleConnection.privateCreateStatement(OracleConn
ection.java:772)
at oracle.jdbc.driver.OracleConnection.createStatement(OracleConnection.
java:712)
- locked <02FCA890> (a oracle.jdbc.driver.OracleConnection)
at JdbcTest.main(JdbcTest.java:11)
"VM Thread" prio=5 tid=0x009E5030 nid=0xde0 runnable
"VM Periodic Task Thread" prio=10 tid=0x009E6E00 nid=0xdd0 waiting on condition
"Suspend Checker Thread" prio=10 tid=0x009E7750 nid=0xdcc runnable -
Sender JDBC Adapter hang after network problem ?
Hi,
I got problem with Sender JDBC Adapter. in the normal condition it is working fine. no problem at all.
The problem coming after network connection problem within XI and database for about more than 24 hours. After the connection resume the Sender JDBC Adapter doesn't want to pickup the data.
Communication Channel Log Showing (Without finish Processing).
6/16/08 5:49:04 PM Processing started
6/16/08 5:48:04 PM Processing started
6/16/08 5:47:04 PM Processing started
6/16/08 5:46:04 PM Processing started
6/16/08 5:45:04 PM Processing started
In normal Communication Channel Showing :
6/16/08 5:33:39 PM efcbd379-6b57-4922-364f-9c047e82ac1b Polling interval started. Length: 30.0 seconds
6/16/08 5:33:39 PM efcbd379-6b57-4922-364f-9c047e82ac1b Processing finished successfully
6/16/08 5:33:39 PM Processing started
6/16/08 5:33:09 PM efcbd379-6b57-4922-364f-9c047e82ac1b Polling interval started. Length: 30.0 seconds
6/16/08 5:33:09 PM efcbd379-6b57-4922-364f-9c047e82ac1b Processing finished successfully
6/16/08 5:33:09 PM Processing started
The problem resolve after restart the whole XI system. is there any other way to solve the problem without restarting the whole xi server. Because i have tried to stop and start the communication channel but still doesn't work until restart the xi. server.
Please advise.
Thank you and Best Regards
FernandCheck JDBC FAQ note 831162
7. Network-Level Connection Problems
Q: The TCP/IP connection to my database host is running over an unreliable network connection, i.e. the connection is sometimes interrupted. Consequently, I sporadically receive an SQLException regarding a closed connection in the system trace or audit log or the connection as well as the JDBC Adapter channel are hanging.
How can I work around this connectivity issue?
A: Enable the "Advanced Mode" for the respective JDBC Adapter channel and select the option "Disconnect from Database After Processing each Message".
Note that this might put additional load on your DBMS due to the creation of a new database connection for each message.
If you are connecting to an Oracle database, also refer to question #10 for an alternative solution. -
Sql statement hanging in prod. fast in dev.
Hi,
Sql statement is hanging in production.
In development it is executing in 2 secs.
From explainplan , noticed that taking different indexes.
I have posted the staement and explain plan (prod and dev) below.
Statement:
SELECT
REP_V_SERVICE_REQUEST.SERVICE_REQ_ID,
REP_V_ACTIVITY.EXTERNAL_REF,
REP_V_ACTIVITY.VENUS_PROBLEM_START,
REP_V_ACTIVITY.VENUS_ALERT_ISSUED,
REP_V_ACTIVITY.VENUS_NOTIFIED,
REP_V_ACTIVITY.ACTIVITY_ID,
REP_V_ACTIVITY.CREATED_BY_WORKGROUP,
REP_V_ACTIVITY.ABSTRACT,
REP_V_ACTIVITY.TIME_TO_VENUS_ALERT,
REP_V_ACTIVITY.TIME_TO_VENUS_ISSUE,
REP_V_ACTIVITY.TIME_TO_VENUS_NOTIFIED,
REP_V_SERVICE_REQUEST.TYPE,
REP_V_SERVICE_REQUEST.SUB_TYPE,
REP_V_SERVICE_REQUEST.CLASSIFICATION_TYPE,
REP_V_SERVICE_REQUEST.CLASSIFICATION_SUB_TYPE,
( REP_V_SERVICE_REQUEST.TIME_OPENED ),
REP_V_SERVICE_REQUEST.CREATED_BY_WORKGROUP,
REP_V_ACTIVITY.VENUS_SENT_TO_SDN,
SR_RESOLVER_WG.WORKGROUP
FROM
REP_V_SERVICE_REQUEST,
REP_V_ACTIVITY,
REP_V_WORKGROUP SR_RESOLVER_WG
WHERE
( SR_RESOLVER_WG.WORKGROUP_ID=REP_V_SERVICE_REQUEST.RESOLUTION_GROUP_ID )
AND ( REP_V_ACTIVITY.SERVICE_REQUEST_ROW_ID=REP_V_SERVICE_REQUEST.SERVICE_REQUEST_ROW_ID )
AND (
REP_V_ACTIVITY.PLANNED_START_TIME BETWEEN '01-JAn-2006' AND '19-Jun-2006'
AND REP_V_ACTIVITY.VENUS_PROBLEM_STATUS NOT IN ('Information', 'Planned')
AND REP_V_ACTIVITY.VENUS_ALERT_STATUS != 'Withdrawn'
AND REP_V_ACTIVITY.CREATED_BY_WORKGROUP LIKE '%SSHD%'
AND REP_V_ACTIVITY.STATUS != 'Cancelled'
AND REP_V_ACTIVITY.CREATED_BY_WORKGROUP NOT LIKE 'GLO_SSHD_MTC'
Exp. plan(prod)
24 SELECT STATEMENT
23 NESTED LOOPS (OUTER)
21 NESTED LOOPS (OUTER)
19 NESTED LOOPS
16 NESTED LOOPS
13 NESTED LOOPS
10 NESTED LOOPS (OUTER)
8 NESTED LOOPS
5 NESTED LOOPS
2 TABLE ACCESS (BY INDEX ROWID), S_ORG_EXT (SIEBEL)
1 INDEX (FULL SCAN), S_ORG_EXT_F13 (SIEBEL)
4 TABLE ACCESS (BY INDEX ROWID), S_BU (SIEBEL)
3 INDEX (UNIQUE SCAN), S_BU_P1 (SIEBEL)
7 TABLE ACCESS (BY INDEX ROWID), S_SRV_REQ (SIEBEL)
6 INDEX (RANGE SCAN), S_SRV_REQ_U2 (SIEBEL)
9 INDEX (UNIQUE SCAN), S_SRV_REGN_P1 (SIEBEL)
12 TABLE ACCESS (BY INDEX ROWID), SERVICE_REQUEST (CRMREP_REP)
11 INDEX (UNIQUE SCAN), PK_SR (CRMREP_REP)
15 TABLE ACCESS (BY INDEX ROWID), S_EVT_ACT (SIEBEL)
14 INDEX (RANGE SCAN), S_EVT_ACT_F14 (SIEBEL)
18 TABLE ACCESS (BY INDEX ROWID), ACTIVITY (CRMREP_REP)
17 INDEX (UNIQUE SCAN), PK_A (CRMREP_REP)
20 INDEX (RANGE SCAN), S_EVT_MAIL_U1 (SIEBEL)
22 INDEX (RANGE SCAN), S_EVT_ACT_X_U1 (SIEBEL
Exp plan(Dev):
24 SELECT STATEMENT
23 NESTED LOOPS (OUTER)
21 NESTED LOOPS (OUTER)
19 NESTED LOOPS
16 NESTED LOOPS
13 NESTED LOOPS (OUTER)
11 NESTED LOOPS
8 NESTED LOOPS
5 NESTED LOOPS
2 TABLE ACCESS (BY INDEX ROWID), S_EVT_ACT (SIEBEL)
1 INDEX (RANGE SCAN), S_EVT_ACT_M8 (SIEBEL)
4 TABLE ACCESS (BY INDEX ROWID), S_SRV_REQ (SIEBEL)
3 INDEX (UNIQUE SCAN), S_SRV_REQ_P1 (SIEBEL)
7 TABLE ACCESS (BY INDEX ROWID), S_ORG_EXT (SIEBEL)
6 INDEX (UNIQUE SCAN), S_ORG_EXT_U3 (SIEBEL)
10 TABLE ACCESS (BY INDEX ROWID), S_BU (SIEBEL)
9 INDEX (UNIQUE SCAN), S_BU_P1 (SIEBEL)
12 INDEX (UNIQUE SCAN), S_SRV_REGN_P1 (SIEBEL)
15 TABLE ACCESS (BY INDEX ROWID), SERVICE_REQUEST (REPORT)
14 INDEX (UNIQUE SCAN), PK_SR (REPORT)
18 TABLE ACCESS (BY INDEX ROWID), ACTIVITY (REPORT)
17 INDEX (UNIQUE SCAN), PK_A (REPORT)
20 INDEX (RANGE SCAN), S_EVT_MAIL_U1 (SIEBEL)
22 INDEX (RANGE SCAN), S_EVT_ACT_X_U1 (SIEBEL)
I checked the v$session_wait while it is hanging,
It is waiting for table s_evt_act (prod. 1.6 crores,dev. 1 crore)
In development it is accessing S_EVT_ACT_M8 (SINGLE COLUMN)index,in production
it is accessing S_EVT_ACT_F14(COMBN. TWO COLUMNS BUT DIFFERENT FROM PRODUCTION).
Thanks,
kumar.This query is not executing for last 5 to 6 months.
I am new to this issue.
pls find the outof v$session_event for this session.
It is waiting for db file sequential read and the wait is keep on increasing.
SID EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED AVERAGE_WAIT MAX_WAIT TIME_WAITED_MICRO
43 db file sequential read 141459 0 130565 1 66 1305647401
43 db file scattered read 77437 0 54259 1 466 542587342
43 direct path write 1222 0 867 1 26 8671937
43 buffer busy waits 570 0 318 1 4 3175286
43 SQL*Net message to client 339 0 0 0 0 866
43 SQL*Net message from client 338 0 84716 251 32623 847156015
43 latch free 14 12 6 0 2 59905
43 direct path read 6 0 1 0 0 12290
43 log file sync 1 0 0 0 0 2268
Maybe you are looking for
-
Safari and Mail no longer remember my passwords
Safari and Mail no longer remember my passwords. Worked yesterday. Recently updated to 10.5.1 and added Text Expander and PTHPasteboard. Turned them both off. Rebooted. Running 10.5.1 on Intel Pro Mac. Ran First Aid on Keychain Access and says its ok
-
I/O error result code= -36 ???? Please help!!
Im running studio with apogee duet, just got the apple care (god bless it) superdrive replacement, now I get audio input output functioning realtime, but *** soon as I attempt to record the error pops up. I cant find anyone else with this problem, an
-
how to sync to google chrome, how does this work
-
In sun's j2sdkee:abou JNDI,I don't know the two paramters' value
In sun's j2sdkee, I deploy my first EJB, and I run a client code to test it. but I don't know the two paramters' value: java.naming.provider.url (Context.PROVIDER_URL) and java.naming.factory.initial (Context.INITIAL_CONTEXT_FACTORY) Do I need to ins
-
2 users icloud control panel same pc
I am trying to install icloud control panel on 2 seperate accounts on my win 7 pc. I have it installed and working fine on my account on the laptop, and when I log into my wifes laptop user account and try to install a copy of icloud control panel fo