Rahul B. Shah

Greenhorn
+ Follow
since Jan 17, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rahul B. Shah

Hello,
i have following .txt file

aaa<!--UserID-->aaa
aaa<!--app name-->aaa
aaa<!--Error-->aaa
aaa<!--LDAPGroup-->aaa

I want to replace <!--UserID-->,<!--app name-->,<!--Error-->,<!--LDAPGroup-->,so output should be

aaaRahulaaa
aaaMyAppaaa
aaaMyErroraaa
aaaMyLDAPaaa

I have written following code which replaces only last line aaa<!--LDAPGroup-->aaa

private String getForm1(String app,String userId,String error,String ldapGrp){

String replaceStr="";
BufferedReader br;

try{

File file = new File("input.txt");
br = new BufferedReader(new FileReader(file));
String line="";
String oldText="";
String newText="";

while((line = br.readLine())!= null){

oldText += line + "\r\n";

}

br.close();

newText = oldText.replaceAll("<!--UserID-->",userId);

newText = oldText.replaceAll("<!--app name-->",app);

newText = oldText.replaceAll("<!--Error-->",error);

newText = oldText.replaceAll("<!--LDAPGroup-->",ldapGrp);


FileWriter writer = new FileWriter("input.txt");
writer.write(newText);
writer.close();

System.out.println("Done ...");

}catch(Exception e){

System.out.println("Exception :"+ e.toString());
}

return replaceStr;
}

Thank-You
Rahul Shah
6 years ago
Hello Ifteqar,
Log4j configuration files means log4j.properties file ?
If yes then here it is :

# Set root category priority to INFO and its only appender to CONSOLE.

log4j.rootLogger=debug, stdout
#log4j.rootCategory=DEBUG,LOGFILE

# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=- %m%n

# LOGFILE is set to be a File appender using a PatternLayout.
#log4j.appender.LOGFILE=org.apache.log4j.FileAppender
#log4j.appender.LOGFILE.File=c:\\axis.log
#log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
#log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

If log4j.properties is not the configuration file then could you guide which one is configuration file ?

Thanks,
Rahul
Hello Everybody,
I am trying simple log4j example & getting following message

log4j:WARN No appenders could be found for logger (log4jexample.LogExample).
log4j:WARN Please initialize the log4j system properly.

Following is my code :

package log4jexample;

import java.util.Enumeration;
import java.util.Properties;
import org.apache.log4j.*;

public class LogExample {

static Logger log = Logger.getLogger(LogExample.class.getName());

public static void main(String args[]){

log.debug("Here is some DEBUG");
log.info("Here is some INFO");
log.warn("Here is some WARN");
log.error("Here is some ERROR");
log.fatal("Here is some FATAL");

new LogExample().init();

}

public void init(){

Properties prop = System.getProperties();
Enumeration enumm = prop.propertyNames();

log.info("***** System Environment As Seen By JAVA *****");
log.debug("***** Formate: PROPERTY = VALUE *****");

while(enumm.hasMoreElements()){

String key = (String)enumm.nextElement();
log.info(key +"=" + System.getProperty(key));
}
}
}

Following is my log4j.properties file

# Set root category priority to INFO and its only appender to CONSOLE.

log4j.rootLogger=debug, stdout
#log4j.rootCategory=DEBUG,LOGFILE

# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=- %m%n

# LOGFILE is set to be a File appender using a PatternLayout.
#log4j.appender.LOGFILE=org.apache.log4j.FileAppender
#log4j.appender.LOGFILE.File=c:\\axis.log
#log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
#log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n


I am using Eclipse galileo & i have added log4j.jar in build path & log4j.properties file is present in src folder and once i build the project i can see properties file generating in bin folder where class files are also generated, but still i am getting above message .

Thank-You
Rahul Shah
Thanks Rob,
I have done following :


I get following output on console :

# Lookup Name
Test Lookup 1

#Type
Refresh

First Name
FIRST_NAME

Last Name
LAST_NAME

ORGANIGATION
USER_ORGANIZATION



# Lookup Name
Test Lookup 2

#Type
Append

First Name
FIRST_NAME

Last Name
LAST_NAME

ORGANIGATION
USER_ORGANIZATION

Email
USER EMAIL

& now i am stuck on how to get these values so that i can use in my function ....

[Edit - added code tags - MB]
6 years ago
Hello,
Can anyone guide me how to read csv file & which collection is suitable.

csv file :
Name test
FirstName First_Name
LastName Last_Name

Name test2
FirstName First_Name
LastName Last_Name
Email User_Email
6 years ago
Hello,
can anybody provide me the basic example of how to display data from database & sort it using comparator interface.
Ex. I have Emloyee table with fields as id,name,salary
so it should display according to name & salary.

Thank-You
6 years ago
Hello,
I have created an application which uses struts-tiles & it has menu on left hand side,header,footer & body.
I have created a link on menu part i.e Login & when i click it i can see my login form within body part & i can also see
menu,header & footer .
But as soon as i login & i goto other page & i can see complete page & i cannot see menu,header & footer part, i am struggling
on this issue for past 1 week & dont know how to resolve it, can anyone suggest me how to work this out.

Thank-You
Rahul Shah
6 years ago
Hello,
Thankx everybody for reply,i deployed my project in tomcat=>webapps & it was running,but in eclipse i get same problem.
6 years ago
Hello,
I have created simple struts application & earlier it was running properly but now it shows Web.xml was not found where Web.xml file is
present project. Detailed Error Log:

Aug 8, 2011 1:12:06 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_21\bin\
Aug 8, 2011 1:12:06 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Aug 8, 2011 1:12:06 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 375 ms
Aug 8, 2011 1:12:06 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Aug 8, 2011 1:12:06 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.33
Aug 8, 2011 1:12:06 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Aug 8, 2011 1:12:27 PM org.apache.struts.util.PropertyMessageResources loadLocale
WARNING: Resource org/apache/struts/action/ActionResources_en_US.properties Not Found.
Aug 8, 2011 1:12:27 PM org.apache.struts.util.PropertyMessageResources loadLocale
WARNING: Resource org/apache/struts/action/ActionResources_en.properties Not Found.
Aug 8, 2011 1:12:27 PM org.apache.struts.action.ActionServlet initServlet
SEVERE: The /WEB-INF/web.xml was not found.
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.apache.commons.digester.Digester.createInputSourceFromURL(Digester.java:1938)
at org.apache.commons.digester.Digester.resolveEntity(Digester.java:1615)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1765)
at org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java:1785)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:349)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4266)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Aug 8, 2011 1:12:27 PM org.apache.struts.action.ActionServlet init
SEVERE: Unable to initialize Struts ActionServlet due to an unexpected exception or error thrown, so marking the servlet as unavailable. Most likely, this is due to an incorrect or missing library dependency.
javax.servlet.ServletException: Connection timed out: connect
at org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java:1788)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:349)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4266)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Aug 8, 2011 1:12:27 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet action as unavailable
Aug 8, 2011 1:12:27 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /FreshStruts1 threw load() exception
javax.servlet.UnavailableException: Connection timed out: connect
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:402)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4266)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Aug 8, 2011 1:12:27 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Aug 8, 2011 1:12:27 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Aug 8, 2011 1:12:27 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
Aug 8, 2011 1:12:27 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Aug 8, 2011 1:12:27 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 21521 ms
Aug 8, 2011 1:12:28 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException: Module 'null' not found.
at org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:755)
at org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:735)
at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:818)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:488)
at org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:140)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:84)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)

Thank-You.
6 years ago
Hello Mahendra,
For Database Connection I have created following java file

InitDbase.java

package freshstrutsaction;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JOptionPane;

public class InitDbase
{
private Connection con = null;

public InitDbase()
{
createDBConnection();
}

public void createDBConnection()
{
String serverName,portNo,sid,url,userName,psswd;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("<<<Classes Loaded>>>");
serverName="10.88.176.155";
portNo="1521";
sid="TRAINING";
url="jdbcracle:thin:@" + serverName + ":" + portNo + ":" + sid;
userName="oimuser_jadhavj";
psswd="password";
System.out.println("<<<"+url+">>>");

con = DriverManager.getConnection(url,userName,psswd);
// con = DriverManager.getConnection("jdbcracle:thin:@10.88.176.155:1521:TRAINING","oimuser_jadhavj","password");
if(con == null)
{
MessageBox("Could Not Connect To Database");
System.out.println("<<<Could Not Connect To Database>>>");
}
else
{
MessageBox("Connected To Database");
System.out.println("<<<Connected To Database>>>");
}
}
catch(ClassNotFoundException cnfe)
{
MessageBox("ClassNotFound..."+cnfe.toString());
}
catch(SQLException sqle)
{
MessageBox("SQLException :-"+sqle.toString());
}
}

public void MessageBox(Object obj)
{
JOptionPane.showMessageDialog(null,obj.toString());
}

public Connection getCon()
{
return con;
}
public void setCon(Connection conn)
{
this.con = conn;
}
}
---------------------------------------------------------------------------------------------------------------------------------------

With above code i can establish connection with MySQL & if I use Oracle then it does not connects ,it comes at line
con = DriverManager.getConnection(url,userName,psswd);
and then nothing happens,but when i tried same credentials of oracle with java application, it connects,but for above application for struts
it does not connect & i have ojdb14.jar in lib folder .
6 years ago
Hello,
I am new to struts & trying simple application which involves database,so i created a plain java class which does database connection & from action class i am calling this java class but it seems to be wrong

code ::::

LoginAction.java

package loginapplicationaction;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;

import loginapplicationform.LoginForm;

public class LoginAction extends Action
{
private Connection con=null;
private PreparedStatement pstat=null;
private ResultSet rsTry=null;
private String input="",check="";
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception
{
LoginForm lf = (LoginForm)form;
InitDbase idb = new InitDbase();
con = idb.getCon();
input = lf.getUserName();
System.out.println(input+".........................");
checkDB(input);
if(input.equalsIgnoreCase(check))
{
return mapping.findForward("success");
}
else
{
return mapping.findForward("failure");
}
}

public void checkDB(String msg)
{
String sql="";
try
{
sql = "Select * from product where name='"+msg+"' ";
pstat = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rsTry = pstat.executeQuery();
if(rsTry.next())
{
check = rsTry.getString("Name");
}
}
catch(Exception e)
{

}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------

InitDbase.java

package loginapplicationaction;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import javax.swing.JOptionPane;

public class InitDbase
{
private Connection con = null;
private final Logger myLogger = Logger.getLogger(InitDbase.class);

public InitDbase()
{
createDBConnection();
}

public void createDBConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/trial","root","rahul");
if(con==null)
{
MessageBox("Could Not Connect To Database");
myLogger.info("Connection Not Successfull");
}
else
{
MessageBox("Connection Successfull");
myLogger.info("Connection Successfull");
}
}
catch(ClassNotFoundException cnfe)
{
MessageBox("ClassNotFound..."+cnfe.toString());
myLogger.error("Could Not Find MySQL Connector Class"+cnfe);

}
catch(SQLException sqle)
{
MessageBox("SQLException :-"+sqle.toString());
myLogger.info("Error In CreateDBConnection" + sqle);
}
}

public void MessageBox(Object obj)
{
JOptionPane.showMessageDialog(null,obj.toString());
}

public Connection getCon()
{
return con;
}
public void setCon(Connection conn)
{
this.con = conn;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------

Error.log

2011-08-06 11:39:54,109 [INFO ] org.apache.struts.action.ActionServlet.initChain(ActionServlet.java:1686) - Loading chain catalog from jar:file:/E:/Struts/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/LoginApplication/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml
2011-08-06 11:40:03,921 [INFO ] org.apache.struts.chain.ComposableRequestProcessor.init(ComposableRequestProcessor.java:147) - Initializing composable request processor for module prefix ''
2011-08-06 11:40:04,000 [WARN ] org.apache.struts.util.PropertyMessageResources.loadLocale(PropertyMessageResources.java:352) - Resource org/apache/struts/action/ActionResources_en_US.properties Not Found.
2011-08-06 11:40:04,000 [WARN ] org.apache.struts.util.PropertyMessageResources.loadLocale(PropertyMessageResources.java:352) - Resource org/apache/struts/action/ActionResources_en.properties Not Found.
2011-08-06 11:40:04,015 [WARN ] org.apache.struts.chain.commands.AbstractExceptionHandler.execute(AbstractExceptionHandler.java:95) - Unhandled exception
java.lang.IllegalArgumentException: The path of an ForwardConfig cannot be null
at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:70)
at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
2011-08-06 11:40:04,015 [WARN ] org.apache.struts.chain.commands.ExceptionCatcher.postprocess(ExceptionCatcher.java:165) - Exception from exceptionCommand 'servlet-exception'
java.lang.IllegalArgumentException: The path of an ForwardConfig cannot be null
at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:70)
at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
2011-08-06 11:40:04,015 [ERROR] org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:253) - Servlet.service() for servlet action threw exception
java.lang.IllegalArgumentException: The path of an ForwardConfig cannot be null
at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:70)
at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
--------------------------------------------------------------------------------------------------------------------------------------------------------

i dont know what is missing

Thank-You.
6 years ago
Hello Mahendra,
I tried the way which you suggested & it shows message as "The method getDataSource(HttpServletRequest) is undefined for the type LoginAction" i.e it cannot find getDataSource() method & i guess i gave imported wrong package (import javax.sql.DataSource),but
other packages which has datasource are javax.activation & sun.jdbc.odbc.ee ,so which to use ?
Thanks for replying.
6 years ago
Hello Mahendra,
Thanks for reply & Please have a look at my code & i think i have imported all necessary packages ,but still not able to work it out

package freshstrutsaction;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;

import freshstrutsform.LoginForm;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class LoginAction extends Action
{
private String usrName="";

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception
{
LoginForm loginForm = (LoginForm)form;
usrName = loginForm.getUserName();
System.out.println(usrName);
if(loginForm.getUserName().equalsIgnoreCase(loginForm.getPassword()))
{
return mapping.findForward("success");
}
else
{
return mapping.findForward("failure");
}
}

public void createConnection()
{
DataSource dataSource;
Connection con = null;
try
{
dataSource = getDataSource(request);//problem

}
catch(SQLException sqle)
{

}
}
}
6 years ago
Hello,
I am new to struts & trying to connect oracle database,so i added following code in struts-config.xml

<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property value="oracle.jdbc.driver.OracleDriver" property="driverClassName"/>
<set-property value="jdbcracle:thin:@10.88.176.155:1521" property="url"/>
<set-property value="oimuser_jadhavj" property="username"/>
<set-property value="password" property="password"/>
</data-source>
</data-sources>

Then in action class i am trying to get connection from datasource so after searching in google i found that we have to use

dataSource = getDataSource(request);//problem
myConnection = dataSource.getConnection();
Statement stmt=myConnection.createStatement();
ResultSet rst=stmt.executeQuery("select username from test");

But i cannot fing getDataSource() method,so anyone can please guide how to work this out or any one has link where struts & database
examples are mentioned.

Thank-You.
6 years ago
Thanks Shankar it worked after adding commons-collection.jar
6 years ago