wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes Not connecting to database through log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Not connecting to database through log4j" Watch "Not connecting to database through log4j" New topic
Author

Not connecting to database through log4j

indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Hi

am trying to connect to database and wants to insert one simple row to a table with this log4j.properties file...

log4j.rootLogger=debug,A1

#A1 is Database Appender
log4j.appender.A1 =org.apache.log4j.jdbc.JDBCAppender
log4j.appender.A1.url=jdbc dbc:indu1
log4j.appender.A1.user=scott
log4j.appender.A1.password=indu
#log4j.appender.A1.driver=sun.jdbc.odbc.JdbcOdbcDriver
log4j.appender.A1.oracle=INSERT INTO NAME_PASSWORD values('ppp','ppp')
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

I tested this with one simple testconnection javaclass, and working fine...
But with log4j.properties, the database is not connecting...

can anyone please tell me the reason ...

thanks
indu
[ November 04, 2008: Message edited by: Martijn Verburg ]

thanks,
indu
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Sorry, the right code of log4j.properties file is this...

log4j.rootLogger=debug,A1

#A1 is Database Appender
log4j.appender.A1 =org.apache.log4j.jdbc.JDBCAppender
log4j.appender.A1.url=jdbc dbc:indu1
log4j.appender.A1.user=scott
log4j.appender.A1.password=indu
log4j.appender.A1.driver=sun.jdbc.odbc.JdbcOdbcDriver
log4j.appender.A1.sql=INSERT INTO NAME_PASSWORD values('ppp','ppp')
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

thanks
indu
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
It's me again,

please help me how to insert data to a table with the above log4j.properties file..

Thanks
indu
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi indu,

What's the error you get? What have you done to make the connection?



Can you try like this?

Regards
Ananth Chellathurai
[ November 03, 2008: Message edited by: Ananth Chellathurai ]

Ananth Chellathurai [Walk on software]
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Logger logger = Logger.getLogger(this.getClass());

Connection con=DriverManager.getConnection("jdbc dbc:indu1","scott","indu");


logger.debug("in XXX.jsp...debug");

Here, the console appender,file appender are working fine...but for database, the data is not appending...

thanks
indu
[ November 04, 2008: Message edited by: Martijn Verburg ]
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Are you getting any specific error messages?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
no error message, just the data is not appending..

thanks
indu
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

There must be some sort of error message going on behind the scenes, check the Log4J documentation to see how you can debug/inspect log4j.

Also have you tried making that database connection from that machine to the database in question using those parameters? For example try connecting with your regular SQL client.
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Sorry, I will continue with this..

Now I have changed from type1 driver to thin driver and
the details are :::

Class.forName("oracle.jdbc.OracleDriver");

Connection con = DriverManager.getConnection("jdbc racle:thin:@localhost:1521:Indu", "scott","indu");

the javaclass is connecting fine with the Oracle SQL Developer information I have provided.
but, by using log4j.properties file with the same information
am getting the error message ::::

---->>>> java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

thanks
indu
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Sorry, I didn't get any error message ...
the data is not appending to the table if I am inserting a row by using log4j.properties file.. with the above details..

thanks
indu
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Indu,

Sorry I'm a bit confused by your last two posts, I assume that you were able to successfully connect via a Java class but it still silently fails when you are using log4j?

Can you show us the CLASSPATH of the program you are running?
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
sorry, I am a bit late..

yes, what you told was exactly correct... the connection to the database is fine with javaclass and the connection is failing with log4j.properties file.

and now am getting the error :::

log4j:ERROR Ignoring configuration file [log4j.properties].

am using the code for configuring properties file as
static
{
String propfile ="log4j.properties";
PropertyConfigurator.configure(propfile);
}
private static Logger logger = Logger.getLogger(NewServlet.class.getName());
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
sorry, I am a bit late..

yes, what you told was exactly correct... the connection to the database is fine with javaclass and the connection is failing with log4j.properties file.

and now am getting the error :::

log4j:ERROR Ignoring configuration file [log4j.properties].

am using the code for configuring properties file as
static
{
String propfile ="log4j.properties";
PropertyConfigurator.configure(propfile);
}
private static Logger logger = Logger.getLogger(NewServlet.class.getName());
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Hi, its me again,
please tell me a solution that,
am using JDK 1.4 and oracle 8i and eclipse 3.2.
I added classes12.jar and ojdbc 14.jar in my classpath.

but still am getting the exception as:::

log4j:ERROR Could not find value for key log4j.appender.A3.layout
log4j:ERROR Failed to load driver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

can you please suggest me a solution..

waiting
indu
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

It's telling you it can't find the class for the Oracle driver, double check your CLASSPATH in eclipse and check inside the JAR to make sure that the class actually exists.
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
yes, it has solved ...

and now my question is -->>>

for file appender , the log messages are not appending to the log file when i am using a servlet.
But the log messages are appending fine if am using a javaclass ....

is there any thing specific for a servlet to log messages ??
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Should be fine from a servlet but be very aware as to where the log file is in relation to where your servlet is deployed, if for example you are using relative paths the log file may not be turning up where you expect...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Not connecting to database through log4j
 
Similar Threads
Log4J No appenders
Logging
log4j - display logger.debug(...) from one class to only a specific log file
New to log4j
Database connection through Log4j