aspose file tools*
The moose likes JBoss/WildFly and the fly likes About Pure java driver with JBOSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "About Pure java driver with JBOSS" Watch "About Pure java driver with JBOSS" New topic
Author

About Pure java driver with JBOSS

naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
hi,
I have a classCastException in the code please can any body help me out for this.I have attached the code

package jdbcOdbcbridge;
import java.sql.*;
import javax.naming.*;
import javax.naming.Context;
import javax.sql.DataSource;
import java.util.*;
public class PurejavaDriver {
public static final String JNDINAME="java:/shop";
public static final String INITIAL_CONTEXT_FACTORY="org.jnp.interfaces.NamingContextFactory";//org.jnp.interfaces.NamingContextFactory
publicstatic Connection Con=null;
publicstatic Statement stmt=null;
publicstatic ResultSet rs=null;
publicstatic DataSource datasource;
publicstatic Context ctx;
public static void main(String str[])
{
System.out.println("Main methid");
try
{
Hashtable hash=new Hashtable();
System.out.println("creating the hashtable");
hash.put(Context.INITIAL_CONTEXT_FACTORY,INITIAL_CONTEXT_FACTORY);
System.out.println("creating the Context Factory");
hash.put(Context.PROVIDER_URL,"localhost:1099");
System.out.println("creating the Provider URL");
ctx=new InitialContext(hash);
System.out.println("Context is initilized");
datasource=(DataSource)ctx.lookup(JNDINAME);
Con=datasource.getConnection();
stmt= Con.createStatement();
System.out.println("The statement is created");
rs=stmt.executeQuery("select * from adminlogin");
//boolean noUser = true;
//boolean loginSuccess=false;
while(rs.next())
{
String username=rs.getString(1);
String pass=rs.getString(2);
System.out.println(username);
}
}catch (Exception E)
{
System.out.println("Exception is ---->"+E);
}
}
}

while running this cod ei am getting the runtime exception,(Application server also started that time)
Main methid
creating the hashtable
creating the Context Factory
creating the Provider URL
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/Logger
at org.jnp.interfaces.NamingContext.<clinit>(NamingContext.java:102)
at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:41)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at jdbcOdbcbridge.PurejavaDriver.main(PurejavaDriver.java:26)


Thanks and regards
Naresh govindaswamy


Thanks and Regards<br />Naresh govindaswamy
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/Logger

Its not a ClassCastException you are getting, its a NoClassDefFoundError. Looks like you need to have JBoss's logging classes in your classpath. No idea which of the many Jar files you get with JBos scontains this class, but it will be in there somewhere.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Moving to JBoss since this either about JBoss files or setting a classpath in JBoss.


[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
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

Include the jbossall-client.jar (this can be found in %JBOSS_HOME%/client folder) file in the client's classpath.


[My Blog] [JavaRanch Journal]
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
Originally posted by Jaikiran Pai:
Include the jbossall-client.jar (this can be found in %JBOSS_HOME%/client folder) file in the client's classpath.


hi,
I have included the jar file in the classpath. I am able to initilized the context .Now I am not able to look up the JNDI name.This is what i am getting now as output
Main methid
creating the hashtable
creating the Context Factory
creating the Provider URL
Context is initilized
Exception is ---->javax.naming.NameNotFoundException: shop not bound.

I have started the application server. In that JNDI name also bound in the correct way.I have attached the configuration file for the application server.

<local-tx-datasource>
<jndi-name>shop</jndi-name>
<connection-url>jdbc ostgresql://127.0.0.1:5432/shop</connection-url>;
<driver-class>org.postgresql.Driver</driver-class>
<user-name>postgres</user-name>
<password>postgres</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->

<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

</local-tx-datasource>

Please any body help me out of this.

Thanks and Regards
Naresh Govindaswamy
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

Datasources are by default bound to the java: namespace in the JNDI tree and not available to remote (standalone) clients. Have a look at HowCanIAccessADataSourceFromAClient to access the datasource from client.
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
Originally posted by Jaikiran Pai:
Datasources are by default bound to the java: namespace in the JNDI tree and not available to remote (standalone) clients. Have a look at HowCanIAccessADataSourceFromAClient to access the datasource from client.

hi,
Sorry i am not able to get it anything from that link.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

Add the following line to your datasource file:

naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
Originally posted by Jaikiran Pai:
Add the following line to your datasource file:



hi,
I have already configured that one int xml file i will attach the xml file also
<local-tx-datasource>
<jndi-name>shop</jndi-name>
<connection-url>jdbc ostgresql://127.0.0.1:5432/shop</connection-url>;
<driver-class>org.postgresql.Driver</driver-class>
<user-name>postgres</user-name>
<password>postgres</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->

<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
<use-java-context>false</use-java-context>

</local-tx-datasource>


please help me ou i am looking for this.

Thanks and regards
naresh govindaswamy
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

And you are still seeing the same NameNotFoundException for the 'shop' jndi-name? If yes, then go through this and see if you can figure out the problem.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

And by the way, change

public static final String JNDINAME="java:/shop";


to

naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
hi,
Sorry for this I am not getting the expeceted output still now. I will attached the full code related to that program.

*********java file***********
package jdbcOdbcbridge;
import java.sql.*;
import javax.naming.*;
import javax.naming.Context;
import javax.sql.DataSource;
import java.util.*;
public class PurejavaDriver {
public static final String JNDINAME="shop";
public static final String INITIAL_CONTEXT_FACTORY="org.jnp.interfaces.NamingContextFactory";//org.jnp.interfaces.NamingContextFactory
publicstatic Connection Con=null;
publicstatic Statement stmt=null;
publicstatic ResultSet rs=null;
publicstatic DataSource datasource;
publicstatic Context ctx;
public static void main(String str[])
{
System.out.println("Main methid");
try
{
Hashtable hash=new Hashtable();
System.out.println("creating the hashtable");
hash.put(Context.INITIAL_CONTEXT_FACTORY,INITIAL_CONTEXT_FACTORY);
System.out.println("creating the Context Factory");
hash.put(Context.PROVIDER_URL,"localhost:1099");
System.out.println("creating the Provider URL");
ctx=new InitialContext(hash);
System.out.println("Context is initilized");
datasource=(DataSource)ctx.lookup(JNDINAME);
Con=datasource.getConnection();
stmt= Con.createStatement();
System.out.println("The statement is created");
rs=stmt.executeQuery("select * from adminlogin");
//boolean noUser = true;
//boolean loginSuccess=false;
while(rs.next())
{
String username=rs.getString(1);
String pass=rs.getString(2);
System.out.println(username);
}
}catch (Exception E)
{
System.out.println("Exception is ---->"+E.getMessage());
}
}
}



******Lookup xml file *******
<local-tx-datasource>
<jndi-name>shop</jndi-name>
<connection-url>jdbc ostgresql://127.0.0.1:5432/shop</connection-url>;
<driver-class>org.postgresql.Driver</driver-class>
<user-name>postgres</user-name>
<password>postgres</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
<use-java-context>false</use-java-context>

</local-tx-datasource>

*****Application server Console *******
00:52:06,609 INFO [PostgresDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:ser
vice=LocalTxCM,name=PostgresDS to JNDI name 'java:/PostgresDS'
00:52:06,781 INFO [DefaultDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:serv
ice=LocalTxCM,name=DefaultDS to JNDI name 'java:/DefaultDS'
00:52:15,078 INFO [A] Bound to JNDI name: queue/A
00:52:15,093 INFO [B] Bound to JNDI name: queue/B
00:52:15,093 INFO [C] Bound to JNDI name: queue/C
00:52:15,109 INFO [D] Bound to JNDI name: queue/D
00:52:15,109 INFO [ex] Bound to JNDI name: queue/ex
00:52:15,109 INFO [pricefeeder67] Bound to JNDI name: queue/pricefeeder67
00:52:15,140 INFO [testTopic] Bound to JNDI name: topic/testTopic
00:52:15,156 INFO [securedTopic] Bound to JNDI name: topic/securedTopic
00:52:15,156 INFO [testDurableTopic] Bound to JNDI name: topic/testDurableTopic
00:52:15,156 INFO [testQueue] Bound to JNDI name: queue/testQueue
00:52:15,375 INFO [UILServerILService] JBossMQ UIL service available at : /0.0.0.0:8093
00:52:15,515 INFO [DLQ] Bound to JNDI name: queue/DLQ
00:52:15,546 INFO [shop] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=L
ocalTxCM,name=shop to JNDI name 'java:/shop'
00:52:15,625 INFO [JCAResource] Registration is not done -> stop


***** Arrived Result *****
Main methid
creating the hashtable
creating the Context Factory
creating the Provider URL
Context is initilized
Exception is ---->shop not bound

Please help me out of this. I am looking for this
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

How are you deploying the datasource? What's the name of the file and where do you place it? And which version of JBoss are you using?
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
Originally posted by Jaikiran Pai:
How are you deploying the datasource? What's the name of the file and where do you place it? And which version of JBoss are you using?


hi,
I am using jboss 3.2.6 versio and I am deploying the datasource through Posrgres-ds.xml file.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10210
    
166

I am using jboss 3.2.6 versio


The use-java-context is available only with JBoss 4.0.x and later versions of JBoss. You wont be able to access the datasource from the standalone client in 3.2.x.
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
Originally posted by Jaikiran Pai:


The use-java-context is available only with JBoss 4.0.x and later versions of JBoss. You wont be able to access the datasource from the standalone client in 3.2.x.


hi,
Thanks alot.I will check it let you know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Pure java driver with JBOSS