Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

About Pure java driver with JBOSS

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
author & internet detective
Posts: 40801
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to JBoss since this either about JBoss files or setting a classpath in JBoss.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include the jbossall-client.jar (this can be found in %JBOSS_HOME%/client folder) file in the client's classpath.
 
naresh govindaswmay
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add the following line to your datasource file:

 
naresh govindaswmay
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And by the way, change

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



to

 
naresh govindaswmay
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic