Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java tomme中的此代码数据源配置在没有eclipse的情况下运行,但当我在eclipse中运行时,它给出了错误_Java_Mysql_Eclipse_Datasource - Fatal编程技术网

Java tomme中的此代码数据源配置在没有eclipse的情况下运行,但当我在eclipse中运行时,它给出了错误

Java tomme中的此代码数据源配置在没有eclipse的情况下运行,但当我在eclipse中运行时,它给出了错误,java,mysql,eclipse,datasource,Java,Mysql,Eclipse,Datasource,我正在使用ApacheTomee数据源将mysql连接到java。这在没有eclipse(juno)的情况下可以正常工作,但当我使用eclipse运行时,会出现错误。 在此url中可以查看错误: 这是我的tomme.xml文件 <?xml version="1.0" encoding="UTF-8"?> <tomee> <Resource id="jdbc/mydb" type="DataSour

我正在使用ApacheTomee数据源将mysql连接到java。这在没有eclipse(juno)的情况下可以正常工作,但当我使用eclipse运行时,会出现错误。 在此url中可以查看错误:

这是我的tomme.xml文件

         <?xml version="1.0" encoding="UTF-8"?>
            <tomee>
              <Resource id="jdbc/mydb" type="DataSource">
                JdbcDriver com.mysql.jdbc.Driver    
                JdbcUrl jdbc:mysql://localhost:3306/ops
                UserName root
                Password     
                JtaManaged true    
             </Resource>
            </tomee>
我写的这段代码只是为了测试。这段代码在没有eclipse的情况下工作很好,还有一件事,当我在eclipse中运行这个项目时,它给出了hsqldb而不是mysql的例外,您可以在这里查看完整的堆栈trance。

如果在tomee.xml和eclipse中配置数据源,则必须执行此操作 步骤也一样

     Locate your TomEE server configuration in Workspace / Servers(Eclipse)
     Right-click the server project and select Import
     Select General - File System and click Next
     Browse to your <TomEE>/conf folder
     Select the following files for import: logging.properties, system.properties and            tomee.xml
      Click Finish to import the files.
       In the Servers tab, right-click the TomEE server and select Publish to publish the files to the Eclipse metadata folder
在Workspace/Servers(Eclipse)中找到您的TomEE服务器配置
右键单击服务器项目并选择导入
选择“常规-文件系统”,然后单击“下一步”
浏览到您的/conf文件夹
选择以下要导入的文件:logging.properties、system.properties和tomee.xml
单击“完成”导入文件。
在Servers选项卡中,右键单击TomEE服务器并选择Publish以将文件发布到Eclipse元数据文件夹
这会奏效的

                Context initContext = new InitialContext();
          Context envContext  = (Context)initContext.lookup("java:/comp/env");
            DataSource ds = (DataSource)envContext.lookup("jdbc/mydb");
          Connection conn = ds.getConnection();
          Statement stmt=conn.createStatement();
          ResultSet rs=stmt.executeQuery("select * From student_master");
          while(rs.next())
            out.println("the student name is"+rs.getString("SM_StudentName"));
     Locate your TomEE server configuration in Workspace / Servers(Eclipse)
     Right-click the server project and select Import
     Select General - File System and click Next
     Browse to your <TomEE>/conf folder
     Select the following files for import: logging.properties, system.properties and            tomee.xml
      Click Finish to import the files.
       In the Servers tab, right-click the TomEE server and select Publish to publish the files to the Eclipse metadata folder