trodriguesbhPJ 11 de mai. de 2012
Coloca dentro da pasta
glassfish\modules
Abs
lucas.vigano 11 de mai. de 2012
Fala Ricardo Beleza?
A pasta padrão para jars de conexoes é
“<DiretorioDeInstalaçãoGlassFish>/glassfish/libs”
por exemplo:
“C:\glassfish3\glassfish\lib”
Após voce ter copiando o jar pra essa pasta, reinicie o servidor para ele carregar o novo jar, assim provavelmente nao vai mais dar o erro, a não ser que tenha mais algo de errado configurado.
Qualquer coisa posta aew!
Flws
ricardo_batista_alme 14 de mai. de 2012
Consegui deu certo , agora como sou novo em jndi, para eu usar este pool que criei no glassfish , basta somente fazer uma classe no java para fazer o lookup, sem precisar configura nada , como eu uso esta conexão ?
Roger75 14 de mai. de 2012
Na administração, crie um JDBC Resource com seu pool de conexão, com nome por exemplo de “jdbc/__conexao”.
Na app web, você coloca no web.xml algo assim:
<resource-ref>
<description>Conexão ao Banco de dados</description>
<res-ref-name>jdbc/__conexao</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Se for pegar por um servlet, chame o DataSource por um Service Locator pela conexão “jdbc/__conexao”
ricardo_batista_alme 14 de mai. de 2012
Criei no glassfish um JDBC resources com o nome ldbc/_sqlserver , adicionei as tags
<description>Conexão ao Banco de dados</description>
<res-ref-name>jdbc/_sqlServer</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
criei a classe e estou chamando assim
InitialContext initialContext = new InitialContext ();
DataSource dataSource = ( DataSource ) initialContext . lookup ( “ jdbc / _sqlserver ” );
return dataSource . getConnection ();
porem da u seguinte erro:
Mai 14 , 2012 1 : 40 : 18 PM com . sun . enterprise . v3 . server . CommonClassLoaderServiceImpl findDerbyClient
Informações : Cannot find javadb client jar file , derby jdbc driver will not be available by default .
java . lang . RuntimeException : Orb initialization erorr
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 180 )
at com . sun . enterprise . naming . impl . SerialContext . getORB ( SerialContext . java : 364 )
at com . sun . enterprise . naming . impl . SerialContext . getProviderCacheKey ( SerialContext . java : 371 )
at com . sun . enterprise . naming . impl . SerialContext . getRemoteProvider ( SerialContext . java : 401 )
at com . sun . enterprise . naming . impl . SerialContext . getProvider ( SerialContext . java : 346 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 504 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 455 )
at javax . naming . InitialContext . lookup ( Unknown Source )
at br . com . hrtech . hrserviceclient . conexao . ConnectionFactory . getConnection ( ConnectionFactory . java : 20 )
at br . com . hrtech . hrserviceclient . conexao . TesteConexao . main ( TesteConexao . java : 11 )
Caused by : java . lang . NullPointerException
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 152 )
… 9 more
Mai 14 , 2012 1 : 40 : 18 PM br . com . hrtech . hrserviceclient . conexao . ConnectionFactory getConnection
Grave : null
javax . naming . NamingException : Lookup failed for ‘ jdbc / _sqlserver ’ in SerialContext [ myEnv ={ java . naming . factory . initial = com . sun . enterprise . naming . impl . SerialInitContextFactory , java . naming . factory . url . pkgs = com . sun . enterprise . naming , java . naming . factory . state = com . sun . corba . ee . impl . presentation . rmi . JNDIStateFactoryImpl } [ Root exception is javax . naming . NamingException : Unable to acquire SerialContextProvider for SerialContext [ myEnv ={ java . naming . factory . initial = com . sun . enterprise . naming . impl . SerialInitContextFactory , java . naming . factory . url . pkgs = com . sun . enterprise . naming , java . naming . factory . state = com . sun . corba . ee . impl . presentation . rmi . JNDIStateFactoryImpl } [ Root exception is java . lang . RuntimeException : Orb initialization erorr ]]
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 518 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 455 )
at javax . naming . InitialContext . lookup ( Unknown Source )
at br . com . hrtech . hrserviceclient . conexao . ConnectionFactory . getConnection ( ConnectionFactory . java : 20 )
at br . com . hrtech . hrserviceclient . conexao . TesteConexao . main ( TesteConexao . java : 11 )
Caused by : javax . naming . NamingException : Unable to acquire SerialContextProvider for SerialContext [ myEnv ={ java . naming . factory . initial = com . sun . enterprise . naming . impl . SerialInitContextFactory , java . naming . factory . url . pkgs = com . sun . enterprise . naming , java . naming . factory . state = com . sun . corba . ee . impl . presentation . rmi . JNDIStateFactoryImpl } [ Root exception is java . lang . RuntimeException : Orb initialization erorr ]
at com . sun . enterprise . naming . impl . SerialContext . getProvider ( SerialContext . java : 351 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 504 )
… 4 more
Caused by : java . lang . RuntimeException : Orb initialization erorr
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 180 )
at com . sun . enterprise . naming . impl . SerialContext . getORB ( SerialContext . java : 364 )
at com . sun . enterprise . naming . impl . SerialContext . getProviderCacheKey ( SerialContext . java : 371 )
at com . sun . enterprise . naming . impl . SerialContext . getRemoteProvider ( SerialContext . java : 401 )
at com . sun . enterprise . naming . impl . SerialContext . getProvider ( SerialContext . java : 346 )
… 5 more
Caused by : java . lang . NullPointerException
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 152 )
… 9 more
o que esta errado .
tenho o pool criado e o resources e chamei criado a classe no eclipse ,o web.xml esta apontando para o pool criado por que esta procurando pelo derby ?
Roger75 14 de mai. de 2012
Seu pool deve estar configurado para o Derby e não para o SQLServer…
ricardo_batista_alme 14 de mai. de 2012
Mais não tenho nada de Derby aqui na maquina, criei um resource pelo eclipse ele criou o arquivo sun-resources.xml com as tag
<?xml version=“1.0” encoding=“UTF-8”?>
<!DOCTYPE resources PUBLIC “-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN” “http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd ”>
<resources>
<jdbc-resource enabled=“true” jndi-name=“jdbc/_sqlserver” object-type=“user” pool-name=“SQL Server_qualidade_saPool”/>
<jdbc-connection-pool allow-non-component-callers=“false” associate-with-thread=“false” connection-creation-retry-attempts=“0” connection-creation-retry-interval-in-seconds=“10” connection-leak-reclaim=“false” connection-leak-timeout-in-seconds=“0” connection-validation-method=“auto-commit” datasource-classname=“com.microsoft.sqlserver.jdbc.SQLServerDataSource” fail-all-connections=“false” idle-timeout-in-seconds=“300” is-connection-validation-required=“false” is-isolation-level-guaranteed=“true” lazy-connection-association=“false” lazy-connection-enlistment=“false” match-connections=“false” max-connection-usage-count=“0” max-pool-size=“32” max-wait-time-in-millis=“60000” name=“SQL Server_qualidade_saPool” non-transactional-connections=“false” pool-resize-quantity=“2” res-type=“javax.sql.DataSource” statement-timeout-in-seconds="-1" steady-pool-size=“8” validate-atmost-once-period-in-seconds=“0” wrap-jdbc-objects=“false”>
& lt ; property name = "serverName" value = "192.168.0.100" /& gt ;
& lt ; property name = "PortNumber" value = "1433" /& gt ;
& lt ; property name = "DatabaseName" value = "qualidade" /& gt ;
& lt ; property name = "User" value = "sa" /& gt ;
& lt ; property name = "Password" value = "TECH" /& gt ;
& lt ; property name = "URL" value = "jdbc:sqlserver://192.168.0.100:1433;databaseName=qualidade" /& gt ;
& lt ; property name = "driverClass" value = "com.microsoft.sqlserver.jdbc.SQLServerDriver" /& gt ;
</jdbc-connection-pool>
</resources>
e o lazarento esta procurando o derby
Roger75 14 de mai. de 2012
Tente configurar o Glassfish entrando pelo administrador dele, sem ir pelo Eclipse.
ricardo_batista_alme 14 de mai. de 2012
Fiz das duas formas, e o mesmo procura pelo derby,
estou empacado mais vou descrever as etapas.
1- entrei pelo glassfish e configurei o pool de conexão para sqlserver , pinguei quando terminei e o ping foi sucesso.
2- criei o resource escolhando o pool do sqlserver que antes tinha criado.
3- criei a classe
public class ConnectionFactory {
public Connection getConnection() {
try {
InitialContext initialContext = new InitialContext () ;
DataSource dataSource = ( DataSource ) initialContext .lookup ( "..jdbc/teste" ) ;
return dataSource .getConnection () ;
} catch ( NamingException ex ) {
Logger .getLogger ( ConnectionFactory .class .getName ()) .log ( Level .SEVERE , null , ex ) ;
} catch ( SQLException ex ) {
Logger .getLogger ( ConnectionFactory .class .getName ()) .log ( Level .SEVERE , null , ex ) ;
}
return null ;
}
}
4 - chamei o metodo para teste assim
public static void main ( String [] args ) {
// TODO Auto-generated method stub
ConnectionFactory c = new ConnectionFactory ();
c . getConnection ();
5 - Deu o erro.
Mai 14 , 2012 3 : 10 : 37 PM com . sun . enterprise . v3 . server . CommonClassLoaderServiceImpl findDerbyClient
Informações : Cannot find javadb client jar file , derby jdbc driver will not be available by default .
java . lang . RuntimeException : Orb initialization erorr
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 180 )
at com . sun . enterprise . naming . impl . SerialContext . getORB ( SerialContext . java : 364 )
at com . sun . enterprise . naming . impl . SerialContext . getProviderCacheKey ( SerialContext . java : 371 )
at com . sun . enterprise . naming . impl . SerialContext . getRemoteProvider ( SerialContext . java : 401 )
at com . sun . enterprise . naming . impl . SerialContext . getProvider ( SerialContext . java : 346 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 504 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 455 )
at javax . naming . InitialContext . lookup ( Unknown Source )
at br . com . hrtech . hrserviceclient . conexao . ConnectionFactory . getConnection ( ConnectionFactory . java : 18 )
at br . com . hrtech . hrserviceclient . conexao . TesteConexao . main ( TesteConexao . java : 11 )
Caused by : java . lang . NullPointerException
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 152 )
… 9 more
Mai 14 , 2012 3 : 10 : 37 PM br . com . hrtech . hrserviceclient . conexao . ConnectionFactory getConnection
Grave : null
javax . naming . NamingException : Lookup failed for ‘… jdbc / teste ’ in SerialContext [ myEnv ={ java . naming . factory . initial = com . sun . enterprise . naming . impl . SerialInitContextFactory , java . naming . factory . url . pkgs = com . sun . enterprise . naming , java . naming . factory . state = com . sun . corba . ee . impl . presentation . rmi . JNDIStateFactoryImpl } [ Root exception is javax . naming . NamingException : Unable to acquire SerialContextProvider for SerialContext [ myEnv ={ java . naming . factory . initial = com . sun . enterprise . naming . impl . SerialInitContextFactory , java . naming . factory . url . pkgs = com . sun . enterprise . naming , java . naming . factory . state = com . sun . corba . ee . impl . presentation . rmi . JNDIStateFactoryImpl } [ Root exception is java . lang . RuntimeException : Orb initialization erorr ]]
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 518 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 455 )
at javax . naming . InitialContext . lookup ( Unknown Source )
at br . com . hrtech . hrserviceclient . conexao . ConnectionFactory . getConnection ( ConnectionFactory . java : 18 )
at br . com . hrtech . hrserviceclient . conexao . TesteConexao . main ( TesteConexao . java : 11 )
Caused by : javax . naming . NamingException : Unable to acquire SerialContextProvider for SerialContext [ myEnv ={ java . naming . factory . initial = com . sun . enterprise . naming . impl . SerialInitContextFactory , java . naming . factory . url . pkgs = com . sun . enterprise . naming , java . naming . factory . state = com . sun . corba . ee . impl . presentation . rmi . JNDIStateFactoryImpl } [ Root exception is java . lang . RuntimeException : Orb initialization erorr ]
at com . sun . enterprise . naming . impl . SerialContext . getProvider ( SerialContext . java : 351 )
at com . sun . enterprise . naming . impl . SerialContext . lookup ( SerialContext . java : 504 )
… 4 more
Caused by : java . lang . RuntimeException : Orb initialization erorr
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 180 )
at com . sun . enterprise . naming . impl . SerialContext . getORB ( SerialContext . java : 364 )
at com . sun . enterprise . naming . impl . SerialContext . getProviderCacheKey ( SerialContext . java : 371 )
at com . sun . enterprise . naming . impl . SerialContext . getRemoteProvider ( SerialContext . java : 401 )
at com . sun . enterprise . naming . impl . SerialContext . getProvider ( SerialContext . java : 346 )
… 5 more
Caused by : java . lang . NullPointerException
at org . glassfish . enterprise . iiop . api . GlassFishORBHelper . getORB ( GlassFishORBHelper . java : 152 )
… 9 more
não consigo usar este pool
ricardo_batista_alme 14 de mai. de 2012
Acho que o meu problema seria resolvido setando as propriedades
Properties props = new Properties ();
props . put ( Context . INITIAL_CONTEXT_FACTORY , “ org . jnp . interfaces . NamingContextFactory ” );
props . put ( Context . PROVIDER_URL , “ localhost : 1099 ” );
InitialContext ctxt = new InitialContext ( props );
factory =( QueueConnectionFactory ) ctxt . lookup ( “ ConnectionFactory ” );
porém existe exemplo somente para o servidor jboss , ele usa a classe NamingContextFactory , será que existe uma classe dessa para o glassfish
Roger75 14 de mai. de 2012
Por que você colocou esse dois pontos na string “…jdbc/teste”? Pelo erro, não está achando essa referência.
ricardo_batista_alme 14 de mai. de 2012
Desculpa esse pontos foi erro de digitação eles não existem no fonte
ricardo_batista_alme 15 de mai. de 2012
Consegui criar o que faltava ,agora aparece o seguinte erro
javax.naming.NamingException: Lookup failed for ‘java:comp/env/jdbc/_sqlserver’ in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
alguém já pegou esse erro se pegou como resolveu ?