| |

VerySource

 Forgot password?
 Register
Search
View: 1023|Reply: 7

JNDI get data source

[Copy link]

2

Threads

12

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-10-14 11:00:02
| Show all posts |Read mode
I'm under JB
Driver:
weblogic.jdbc.mssqlserver4.Driver
URL:
jdbc:weblogic:mssqlserver4:News@localhost:1433
Database name:
weblogic:mssqlserver4:News@localhost:1433
JNDI name:
DataSource
Realize the connection of the database (the data source of weblogic is not?)

Now i quote this data source
These packages are imported:
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
The procedure to obtain the data source is as follows:
    public Connection getConnection() throws Exception {
   try {
     Context ctx = new InitialContext();
     javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("DataSource");
     return ds.getConnection();
   } catch (Exception e) {
     System.out.println("Cannot get data source");
     e.printStackTrace();
     return null;
   }
}

But when I call the entity BEAN to insert into the database, I always say that the data source cannot be found.

Please give me some advice
Reply

Use magic Report

2

Threads

12

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-10-14 16:00:01
| Show all posts
I always reported this error: Why is it that I don’t know if I didn’t configure it correctly or something else?
javax.naming.NameNotFoundException: Unable to resolve'Employee'. Resolved'' [Root exception is javax.naming.NameNotFoundException: Unable to resolve'Employee'. Resolved'']; remaining name'Employee'
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:191)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:315)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:250)
at weblogic.jndi.internal.ServerNamingNode_900_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:374)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:362)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at empbmpapp.EmployeeTestClient1.initialize(EmployeeTestClient1.java:55)
at empbmpapp.EmployeeTestClient1.<init>(EmployeeTestClient1.java:43)
at empbmpapp.EmployeeTestClient1.main(EmployeeTestClient1.java:353)
Caused by: javax.naming.NameNotFoundException: Unable to resolve'Employee'. Resolved''
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1123)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:250)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:204)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:503)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:224)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:393)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:389)
at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:56)
at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:903)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)
java.lang.NullPointerException
at empbmpapp.EmployeeTestClient1.main(EmployeeTestClient1.java:356)
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-10-14 18:45:01
| Show all posts
Context env = (Context) new InitialContext().lookup("java:comp/env");
        DataSource source = (DataSource) env.lookup("xxxx");//This place should be consistent with the name in conf
Reply

Use magic Report

2

Threads

12

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-10-14 19:30:01
| Show all posts
xia now reports this error again
I changed to
   Context env = (Context) new InitialContext().lookup("java:comp/env");
        DataSource source = (DataSource) env.lookup("DataSource");//This place should be consistent with the name in conf

cykcui21said that in the lookup("xxxx"), did you write the data source? I wrote it and he reported the error below
C:\bea\jdk150_03\bin\javaw -classpath "F:\EJB\regrter\classes; C:\bea\weblogic90\server\lib\weblogic_sp.jar; C:\bea\weblogic90\server\lib\weblogic.jar; C:\bea\weblogic90\server\lib\webservices.jar; C:\bea\weblogic90\javelin\lib\javelinx.jar; C:\bea\weblogic90\common\lib\log4j.jar; C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib\antlr. jar; C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib\commons-beanutils.jar; C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib\commons-collections.jar; C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib\commons-digester.jar; C:\Borland\JBuilder2016\thirdparty\jakarta-struts- 1.2-lib\commons-fileupload.jar;C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib\commons-logging.jar;C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib1 uo1commons-validator.jar; C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib\jakarta-oro.jar; C:\Borland\JBuilder2016\thirdparty\jakarta-struts-1.2-lib\struts.jar; F:\Y2\J2EE\driver\mssqlserver4v65.jar; C:\bea\jdk150_03\lib\tools.jar; C:\bea\jdk150_03\lib\dt.jar; C:\bea\jdk150_03\lib\htmlconverter.jar; C:\bea\jdk150_03\lib\jconsole.jar; C:\bea\jdk150_03\sample\jnlp\servlet\jnlp.jar; C:\bea\jdk150_03\sample\jnlp\servlet\jnlp-servlet.jar; C:\bea\jdk150_03\sample\jnlp\servlet\jardiff.jar; C:\bea\jdk150_03\jre\lib\jsse.jar; C:\bea\jdk150_03\jre\lib\im\indicim.jar; C:\bea\jdk150_03\jre\lib\im\thaiim.jar; C:\bea\jdk150_03\jre\lib\deploy.jar;C:\bea\jdk150_03\jre\lib\jce.jar;C:\bea\jdk150_03\jre\uo1lib\exta150_03\uo\uo1exta\lib\exta1 uo1dnsns.jar; C:\bea\jdk150_03\jre\lib\ext\sunjce_provider.jar; C:\bea\jdk150_03\jre\lib\ext\sunpkcs11.jar; C:\bea\jdk150_03\jre\lib\charsets.jar; C:\bea\jdk150_03\jre\lib\rt.jar; C:\bea\jdk150_03\jre\lib\plugin.jar "regrter.UserInfoTestClient1
javax.ejb.CreateException: java.lang.NullPointerException
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:191)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:315)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:250)
at regrter.UserInfo_1571he_HomeImpl_900_WLStub.create(Unknown Source)
at regrter.UserInfoTestClient1.main(UserInfoTestClient1.java:211)
Caused by: javax.ejb.CreateException: java.lang.NullPointerException
at regrter.UserInfoBean.ejbCreate(UserInfoBean.java:49)
at regrter.UserInfo_1571he_Impl.ejbCreate(UserInfo_1571he_Impl.java:263)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at weblogic.ejb20.manager.DBManager.create(DBManager.java:1371)
at weblogic.ejb20.manager.DBManager.remoteCreate(DBManager.java:1319)
at weblogic.ejb20.internal.EntityEJBHome.create(EntityEJBHome.java:269)
at regrter.UserInfo_1571he_HomeImpl.create(UserInfo_1571he_HomeImpl.java:80)
at regrter.UserInfo_1571he_HomeImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:503)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:224)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:393)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:389)
at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:56)
at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:903)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-10-14 19:45:01
| Show all posts
Have you configured the data source in the configuration file?
Reply

Use magic Report

2

Threads

12

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-10-14 20:00:01
| Show all posts
not yet
Inside JB
I don’t know what to do. Don’t laugh. Haha
cykcui21give some pointers
Reply

Use magic Report

2

Threads

12

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-10-14 20:15:01
| Show all posts
Okay, the above problem is solved
But why
I insert the database is always empty
  I used him to insert data
try {
            System.out.println("ejbCreate() method is called");
            con = getConnection();
            String sqlStr = "insert into UserIfometion(UserName,Userpwd,"
                            + "RealName,sex,UserItrduce)"
                            + "values ​​(?,?,?,?,?)";
            pstmt = con.prepareStatement(sqlStr);
            pstmt.setString(1, username);
            pstmt.setString(2, userpwd);
            pstmt.setString(3, realname);
            pstmt.setString(4, sex);
            pstmt.setString(5, useritrduce);
            System.out.println(sqlStr);
            System.out.println("888888888888888888888888888888888888888");
            pstmt.executeUpdate();
            pstmt.execute();
            System.out.println(username);
            System.out.println(userpwd);
            System.out.println(realname);
            System.out.println(sex);
            System.out.println(useritrduce);
            
            System.out.println("dhhhhhhhhhhhhhhhhhddddddddddd oh");

            return null;
        } catch (Exception e) {
            throw new CreateException(e.toString());
        } finally {
            try {
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                if (con != null) {
                    con.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
Below is the test side
try{
            home.create("Yang Yongqi","66113576","Gardenia","Male","TNND");
            
        }catch(Exception e){}

I can display the value of the test terminal but I cannot insert it
But I have an auto-incremented field whose value is changing
          TNND
Reply

Use magic Report

2

Threads

12

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-10-14 20:30:01
| Show all posts
Get it done
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list