• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Not connecting to database through log4j

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's me again,

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

Thanks
indu
 
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you getting any specific error messages?
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no error message, just the data is not appending..

thanks
indu
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic