File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes problem connecting to multiple data sources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem connecting to multiple data sources" Watch "problem connecting to multiple data sources" New topic
Author

problem connecting to multiple data sources

nomai altamimi
Greenhorn

Joined: Jan 13, 2012
Posts: 6
hello

while i was working on a project i faces a problem when trying to make my application connect to a multiple data sources


i am working on a web application which require to connect to 2 diffrent data sources

the application behavior :

First the application connects to servlet ( AppServlet )

inside doGet servlet method , I directly connect to a DAO and the DAO connects to the first Data source and brings some info from it

then the user has to fill some fields and press the submit button

the submit button sends info to the servlet ( AppServlet )

inside doPost servlet method , I direcly connect to a DAO and the Dao connects to the Second Data source and stores info in DB

and each data source has its own username and password

and i can connect to the first data source successfully

but the problem is when i try to store the info into DB using the second data source

the server takes the username and password of the second data source and try to use it in the first Data source's Data Base URL

so it keep showing authenticating failed exception


and below data sources from my mssql-ds.xml file




so the problem is the server takes Username: SecondUser & Password : SecondPass and try to use it in DB URL1


i am using JBoss 4.2.2

and using SQL server as my database server


any one can help ?
Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90

Can you post error logs ? We would get a better idea.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

You seem to think that the problem is related to "multiple data sources". Then why don't you test that theory? Write some other code which only connects to your second data source. If the problem was occurring because you connected to two data sources in the same request, then it shouldn't occur in this other code.
nomai altamimi
Greenhorn

Joined: Jan 13, 2012
Posts: 6
hello Dhaval J. Patel

this is the ERROR log

2012-06-20 17:13:16,082 ERROR [STDERR] java.sql.SQLException: Login failed for user 'SecondUser'.
2012-06-20 17:13:16,082 ERROR [STDERR] at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
2012-06-20 17:13:16,083 ERROR [STDERR] at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
2012-06-20 17:13:16,084 ERROR [STDERR] at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
2012-06-20 17:13:16,086 ERROR [STDERR] at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
2012-06-20 17:13:16,089 ERROR [STDERR] at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
2012-06-20 17:13:16,090 ERROR [STDERR] at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
2012-06-20 17:13:16,091 ERROR [STDERR] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedStatement.java:562)
2012-06-20 17:13:16,092 ERROR [STDERR] at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:209)
2012-06-20 17:13:16,094 ERROR [STDERR] at com.neno.webApp.dao.CallSP.sendInformation(CallSP.java:114)
2012-06-20 17:13:16,095 ERROR [STDERR] at com.neno.webApp.servlets.AppServlet.doPost(HafizJPCservlet.java:83)
2012-06-20 17:13:16,104 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
2012-06-20 17:13:16,105 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
2012-06-20 17:13:16,108 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
2012-06-20 17:13:16,109 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2012-06-20 17:13:16,111 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
2012-06-20 17:13:16,112 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
2012-06-20 17:13:16,121 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2012-06-20 17:13:16,122 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
2012-06-20 17:13:16,125 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
2012-06-20 17:13:16,126 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
2012-06-20 17:13:16,128 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
2012-06-20 17:13:16,129 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
2012-06-20 17:13:16,138 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2012-06-20 17:13:16,139 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
2012-06-20 17:13:16,142 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2012-06-20 17:13:16,143 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
2012-06-20 17:13:16,144 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
2012-06-20 17:13:16,146 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
2012-06-20 17:13:16,155 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
2012-06-20 17:13:16,156 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)


and thank you Paul

i will write other code which connects only to my second data source and i will tell you the result
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

nomai altamimi wrote:2012-06-20 17:13:16,082 ERROR [STDERR] java.sql.SQLException: Login failed for user 'SecondUser'.

Either the username is incorrect, or the password is incorrect, or this user cannot login for some other reason.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
nomai altamimi
Greenhorn

Joined: Jan 13, 2012
Posts: 6
Rob Spoor wrote:
nomai altamimi wrote:2012-06-20 17:13:16,082 ERROR [STDERR] java.sql.SQLException: Login failed for user 'SecondUser'.

Either the username is incorrect, or the password is incorrect, or this user cannot login for some other reason.


yes i know the username is not correct

because like i mentioned in my first post

the server takes the username and password of first data source and try to use it to access the second data source

( so , for sure the username and password wont be accepted )





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem connecting to multiple data sources