This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes sql server logs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sql server logs" Watch "sql server logs" New topic
Author

sql server logs

michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I have an entity that inserts few records in a table. This is throwing exception at the time of execution. Is there a way I can lookup more detailed information in SQL Server logs and figure out why the transactions are not succeeding? I know this is a database question and probably not posted in the right forum. But in case anyone knows...
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Michael,
This forum is appropriate for database questions too. Let's start with the information you do have. What does the exception say? Have you looked at the stack trace generated by the exception?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I ran a standalone client from a different JVM. Right now I don't have the exact stack trace because it happened sometime back. Then I checked with application server logs (application server is on another JVM). Log entries are:<code>15:01:32,500 INFO [OpenEJB] invoking method create on a1/AccountBean
15:01:33,218 INFO [OpenEJB] finished invoking method create
15:01:37,703 INFO [Transaction] TX Required: Started transaction org.apache.geronimo.transaction.manager.TransactionImpl@115e9a8
15:01:38,250 INFO [Runtime] Starting OpenJPA 1.0.3
15:01:38,640 INFO [Transaction] TX Required: setRollbackOnly() on transaction org.apache.geronimo.transaction.manager.TransactionImpl@115e9a8
15:01:38,656 INFO [Transaction] TX Required: Rolling back transaction org.apache.geronimo.transaction.manager.TransactionImpl@115e9a8
</code>.
I wanted to know how I could check SQL server 2005 express logs.
Apurv Adarsh
Greenhorn

Joined: Feb 07, 2009
Posts: 12
Couldn't figure out the exact reason, but most of the time I got this msg, either there was a problem with my insert script like inserting null into non nullable fields, or giving wrong spellings.
Please check you sql once.
Also, have look in your log4j for any connection error.

Also try looking for any specific error code from sql engine in log4j.
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I searched for log4j files but none of them have been modified recently.
I am not using sql. I am using annotations and setting the field values and then calling the persist() method of EntityManager object. Code is given here:
<code>
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.*;
@Entity
public class AccountNtt implements Serializable {
@Id
public String accountNumber;
public String accountType;
public String ownerName;
public int balance;
public AccountNtt() {
}
}
</code>
Table is
<code>USE [dra]
GO
/****** Object: Table [dbo].[AccountNtt] Script Date: 02/08/2009 16:52:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[AccountNtt](
[accountNumber] [varchar](20) NOT NULL,
[accountType] [varchar](20) NULL,
[ownerName] [varchar](20) NULL,
[balance] [int] NULL,
CONSTRAINT [PK_AccountNtt] PRIMARY KEY CLUSTERED
(
[accountNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF</code>
Business interface is
<code>import javax.ejb.Remote;
import java.util.*;
@Remote
public interface Account {
void createAccountNtt(AccountNtt a);
}</code>
Bean is
<code>import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.Remote;
import javax.persistence.PersistenceContext;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@Stateless
@Remote(Account.class)
public class AccountBean implements Account {
@PersistenceContext(unitName="bnk")
EntityManager manager;
public void createAccountNtt(AccountNtt a) {
manager.persist(a);
}
}</code>
Client code is
<code>
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.*;
import java.util.Properties;
import java.util.*;
import javax.ejb.EJBException;
public class BankClient {
public static void main(String[] args) {
try {
AccountNtt a10 = new AccountNtt();
a10.accountNumber = "3833";
a10.accountType = "savings";
a10.ownerName = "bailey";
a10.balance = 2524;
Properties p = new Properties();
p.load(new FileInputStream("jndi.properties"));
p.put("openejb.authentication.realmName","geronimo-admin");
InitialContext ctx = new InitialContext(p);
Account a = (Account) ctx.lookup("AccountBeanRemote");
a.createAccountNtt(a10);
}
catch(Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}</code>
Apurv Adarsh
Greenhorn

Joined: Feb 07, 2009
Posts: 12
Code looks fine to me
But when you say that the code is giving exceptions, It should be displayed when you do a "ex.printStackTrace()".
How did you know that it is giving you exceptions???
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
javax.ejb.EJBException: Unknown Container Exception: java.rmi.RemoteException: Cannot read the response from the server. The class for an object being returned is not located in this exception:; nested exception is: java.lang.ClassNotFoundException: org.apache.openjpa.persistence.ArgumentException...........
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you post the whole stacktrace?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I tried to redirect the output using the command:
java BankClient > exception.txt
but it created 0-sized file. Any ideas?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I'm after the stacktrace in the server log.
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
18:42:17,776 INFO [OpenEJB] invoking method create on a1/AccountBean
18:42:17,776 INFO [OpenEJB] finished invoking method create
18:42:20,683 INFO [Transaction] TX Required: Started transaction org.apache.geronimo.transaction.manager.TransactionImpl@45297e
18:42:20,683 INFO [Transaction] TX Required: setRollbackOnly() on transaction org.apache.geronimo.transaction.manager.TransactionImpl@45297e
18:42:20,683 INFO [Transaction] TX Required: Rolling back transaction org.apache.geronimo.transaction.manager.TransactionImpl@45297e
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I have located dra_log file (dr beingn the name of the database) in MSSQL\Data folder. I opened it in notepad but was unable to read it.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You should not need the SQL Server log. Its not going to tell you anything about errors in your application, it will only show the various events you have configured SQL Server to record or any error in SQL Server itself (e.g. missing DLLs, checkdb errors - that sort of thing).

You don't appear to have a server stacktrace. The server log is telling you that something called setRollbackOnly(). Unless you are explicitly calling it yourself the only likely think to cause that is a RuntimeException and that should appear in the logs. There is nothing obviously wrong in the code you have posted so unless you can get the stacktrace all anyone can do is guess what could be wrong. Try sticking a try/catch block round your persist method and see if you can get a stacktrace that way.
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I enclosed persist() ni try ... catch block and ran the program. Application server log entries are given below:
17:22:11,140 INFO [OpenEJB] invoking method create on a1/AccountBean
17:22:11,296 INFO [OpenEJB] finished invoking method create
17:22:14,296 INFO [Transaction] TX Required: Started transaction org.apache.geronimo.transaction.manager.TransactionImpl@12fe3f3
17:22:14,390 INFO [Runtime] Starting OpenJPA 1.0.3
17:22:14,812 INFO [Transaction] TX Required: Committing transaction org.apache.geronimo.transaction.manager.TransactionImpl@12fe3f3
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

michael tall wrote:I enclosed persist() ni try ... catch block and ran the program. Application server log entries are given below:
17:22:11,140 INFO [OpenEJB] invoking method create on a1/AccountBean
17:22:11,296 INFO [OpenEJB] finished invoking method create
17:22:14,296 INFO [Transaction] TX Required: Started transaction org.apache.geronimo.transaction.manager.TransactionImpl@12fe3f3
17:22:14,390 INFO [Runtime] Starting OpenJPA 1.0.3
17:22:14,812 INFO [Transaction] TX Required: Committing transaction org.apache.geronimo.transaction.manager.TransactionImpl@12fe3f3


So presumably you are getting some sort of RuntimeException in your persist method which is now not being rethrown (hence your transaction commits).

You need to get the stacktrace for this exception. This will be in the OpenEJB logs somewhere. I don't know OpenEJB at all, but I'm guessing if you don't see it in the log you are looking at there may be a, error.log or something that errors are being rediected to?
michael tall
Ranch Hand

Joined: Nov 02, 2008
Posts: 61
I played with descriptor files and server property files and ran the program. Log file entries are given below:
17:48:30,937 INFO [OpenEJB] invoking method create on a1.jar/AccountBean
17:48:31,484 INFO [OpenEJB] finished invoking method create
17:48:37,562 INFO [Transaction] TX Required: Started transaction org.apache.geronimo.transaction.manager.TransactionImpl@1ef330a
17:48:38,062 INFO [Runtime] Starting OpenJPA 1.0.3
17:48:38,062 TRACE [Runtime] Properties: openjpa.DataCacheManager: default
openjpa.BrokerFactory: jdbc
openjpa.EntityManagerFactory: default
openjpa.ConnectionRetainMode: on-demand
openjpa.DataCacheTimeout: -1
openjpa.NontransactionalWrite: true
openjpa.IgnoreChanges: false
openjpa.FetchGroups: default
openjpa.jdbc.SubclassFetchMode: join
openjpa.jdbc.FetchDirection: forward
openjpa.InverseManager: false
openjpa.MaxFetchDepth: -1
openjpa.Compatibility: default
openjpa.ConnectionFactoryMode: local
openjpa.RetryClassRegistration: false
openjpa.jdbc.SynchronizeMappings: buildSchema(SchemaAction='add,deleteTableContents')
openjpa.jdbc.Schemas:
openjpa.AutoClear: datastore
openjpa.FetchBatchSize: -1
openjpa.ProxyManager: default
openjpa.OrphanedKeyAction: log
openjpa.Multithreaded: false
openjpa.SavepointManager: in-mem
openjpa.Optimistic: true
openjpa.jdbc.EagerFetchMode: parallel
openjpa.jdbc.DBDictionary: sqlserver(SupportsDeferredConstraints=false)
openjpa.Log: commons
openjpa.QueryCompilationCache: true
openjpa.jdbc.LRSSize: query
openjpa.ManagedRuntime: auto
openjpa.LockTimeout: -1
openjpa.jdbc.ResultSetType: forward-only
openjpa.MetaDataFactory: jpa(Files=/D:/g/geronimo-tomcat6-javaee5-2.1.3/repository/default/a1.jar/1234353719375/a1.jar-1234353719375.jar/ejb.jar)
openjpa.jdbc.DriverDataSource: simple
openjpa.DataCache: false
openjpa.WriteLockLevel: write
openjpa.RuntimeUnenhancedClasses: supported
openjpa.MetaDataRepository: default
openjpa.jdbc.SchemaFactory: dynamic
openjpa.jdbc.TransactionIsolation: default
openjpa.FlushBeforeQueries: true
openjpa.TransactionMode: managed
openjpa.AutoDetach:
openjpa.ClassResolver: org.apache.openjpa.persistence.PersistenceUnitInfoImpl$ClassResolverImpl
openjpa.jdbc.MappingDefaults: jpa
openjpa.DetachState: loaded
openjpa.RetainState: true
openjpa.DynamicDataStructs: false
openjpa.NontransactionalRead: true
openjpa.jdbc.UpdateManager: operation-order
openjpa.LockManager: version
openjpa.ReadLockLevel: read
openjpa.Id: bnk
openjpa.QueryCache: true
openjpa.jdbc.SQLFactory: default
openjpa.BrokerImpl: non-finalizing
openjpa.Sequence: table(Table=OPENJPASEQ, Increment=100)
openjpa.RestoreState: immutable
17:48:42,218 TRACE [MetaData] Using metadata factory "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1e86b36".
17:48:46,015 INFO [JDBC] Using dictionary class "org.apache.openjpa.jdbc.sql.SQLServerDictionary".
17:49:07,625 INFO [Transaction] TX Required: setRollbackOnly() on transaction org.apache.geronimo.transaction.manager.TransactionImpl@1ef330a
17:49:07,625 INFO [Transaction] TX Required: Rolling back transaction org.apache.geronimo.transaction.manager.TransactionImpl@1ef330a
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql server logs
 
Similar Threads
Struts 2.1.6 | Hibernate 3 | Spring 2.5
JDBC Driver: Connection reset by peer: socket write error - ms-sqlserver
Problem with DataSource
Where to see output of hbm2ddl?
Connect to db, simple question !!