Tomcat,MySQL - >无法为连接URL''创建类''的JDBC驱动程序(Tomcat, MySQL -> Cannot create JDBC driver of class '' for connect URL 'null')
我知道这看起来像一个重复的问题,但已尝试stackoverflow和其他论坛中的所有帖子但无济于事。
Apache Tomcat 8.0.32 Amazon RDS运行MySQL 5.6在EC2 Windows服务器上运行tomcat
我的web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> ... <resource-ref> <description>datasource</description> <res-ref-name>jdbc/bbDataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> ... </web-app>
Context.xml位于我的应用程序的META-INF文件夹中:
<?xml version="1.0" encoding="UTF-8"?> <Context path="/ch"> <Resource name="jdbc/bbDataSource" auth="Container" type="javax.sql.DataSource" username="********" password="********" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://*url*:3306/x?zeroDateTimeBehavior=convertToNull"/> </Context>
在ServletContextListener中创建数据源
try { dataSource = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/bbDataSource"); mLogger.log(Level.CONFIG, "Startup - AppContextServletListener - contextInitialized - Created dataSource object: {0}", dataSource); sce.getServletContext().setAttribute("dataSource", dataSource); }
启动期间没有问题。 访问dataSource tomcat时会抛出上述错误。 并且jar文件位于tomcat的lib文件夹中(我怀疑这是问题,因为我在同一个应用程序中也使用了hibernate,它能够访问数据库而没有任何问题)。
另外我注意到以下内容:$ CATALINA_HOME / conf / Catalina / localhost没有'ch.xml' - >尝试复制context.xml并重命名为'ch.xml',但无济于事。
server.xml - >在主机节点下
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="/ch" docBase="ch"></Context> <Context path="/ch/asdasd" docBase="C:\\xasdasd\\asdasd"> </Context>
I know this looks like a repeat question but have tried all posts in stackoverflow and other forums but to no avail.
Apache Tomcat 8.0.32 Amazon RDS running MySQL 5.6 Running tomcat on EC2 windows server
My web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> ... <resource-ref> <description>datasource</description> <res-ref-name>jdbc/bbDataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> ... </web-app>
Context.xml sitting in the META-INF folder of my app:
<?xml version="1.0" encoding="UTF-8"?> <Context path="/ch"> <Resource name="jdbc/bbDataSource" auth="Container" type="javax.sql.DataSource" username="********" password="********" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://*url*:3306/x?zeroDateTimeBehavior=convertToNull"/> </Context>
Creating the datasource in a ServletContextListener
try { dataSource = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/bbDataSource"); mLogger.log(Level.CONFIG, "Startup - AppContextServletListener - contextInitialized - Created dataSource object: {0}", dataSource); sce.getServletContext().setAttribute("dataSource", dataSource); }
No issues during startup. While accessing the dataSource tomcat throws the above error. And the jar file is sitting in the lib folder of tomcat (I doubt this is the problem since I'm also using hibernate in the same application and it is able to access the DB without any issues).
Also I noted the following: $CATALINA_HOME/conf/Catalina/localhost does not have the 'ch.xml' -> Tried copying the context.xml and renaming to 'ch.xml' there but to no avail.
server.xml -> Under the host node
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="/ch" docBase="ch"></Context> <Context path="/ch/asdasd" docBase="C:\\xasdasd\\asdasd"> </Context>
原文:https://stackoverflow.com/questions/36232894
最满意答案
更新:
用类似的东西循环遍历数组并不困难
foreach($messages as $k => $m){ if(strtotime($m['Message']['updatedate']) > strtotime($m['Message']['createdate'])){ $messages[$k]['Message']['NewDate'] = $m['Message']['updatedate']; }else{ $messages[$k]['Message']['NewDate'] = $m['Message']['createdate']; } }
原始答案:
我认为你的
Message.updatedate
总是最新的日期,所以你可以选择它。 但假设由于某种原因不是这种情况,您可以在模型中创建一个虚拟字段:public $virtualFields = array( 'NewDate' => "IF(Message.updatedate > Message.createdate, Message.updatedate, Message.createdate)" );
这使用MySQL
IF()
函数。 如果您不使用MySQL,则必须弄清楚如何使用与数据库类似的操作。http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if
UPDATE:
It's not hard to loop over the array with something like
foreach($messages as $k => $m){ if(strtotime($m['Message']['updatedate']) > strtotime($m['Message']['createdate'])){ $messages[$k]['Message']['NewDate'] = $m['Message']['updatedate']; }else{ $messages[$k]['Message']['NewDate'] = $m['Message']['createdate']; } }
ORIGINAL ANSWER:
I would think that your
Message.updatedate
would always be the newest date, so you could just select that. But assuming that's not the case for some reason, you can create a virtual field in your model:public $virtualFields = array( 'NewDate' => "IF(Message.updatedate > Message.createdate, Message.updatedate, Message.createdate)" );
This uses the MySQL
IF()
function. If you're not using MySQL you'd have to figure out how to do something similar with your database.http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if
相关问答
更多-
我自己的调查结果: CutePDF :将FDF合并为PDF但不支持计算字段 Debenu快速PDF库 :既不是FDF也不是计算字段 PDF-XChange Viewer Pro :支持Javascript但不支持FDF,但非常有用 PDFExpress :支持XFDF(仅限注释),但不支持FDF Adobe PDF Library(通过Datalogics):完全不可理解,不支持任何一种选择 Adobe PDF Library(通过Adobe):没有回答询问 Results of my own invest ...
-
包含作者和日期的git日志的最短输出(The shortest possible output from git log containing author and date)[2023-10-17]
git log --pretty=format:"%h%x09%an%x09%ad%x09%s" 做了这个工作 输出: fbc3503 mads Thu Dec 4 07:43:27 2008 +0000 show mobile if phone is null... ec36490 jesper Wed Nov 26 05:41:37 2008 +0000 Cleanup after [942]: Using timezon ae62afd tobias Tue Nov ... -
尝试这样的事情: 在模型中: /*...*/ $validate = array( 'your_date' => array( 'date' => array( //Add 'ymd' to the rule. 'rule' => array('date', 'ymd'), 'message' => 'Please select a valid birth dat ...
-
尝试这个: 'conditions' => array('DATE(Order.created)' => date('Y-m-d')) 使用MySQL DATE()您需要将created转换为YYYY-MM-DD格式,因为通常是YYYY-MM-DD HH:MM:SS 。 Try this: 'conditions' => array('DATE(Order.created)' => date('Y-m-d')) Using MySQL DATE() you need to convert created ...
-
我的最终解决方案是在bootstrap上: date_default_timezone_set('America/Sao_Paulo'); setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese'); Type::build('time')->useImmutable(); Type::build('date')->useImmutable()->useLocaleParser(); Type::build('datetim ...
-
您可以执行以下操作 Select s1.Id, s1.Name, s2.Alias from Set1 s1, Set2 s2 where s1.Id= s2.Id order by s1.Id, s2.Alias 或者根据您是否要查看“C”行选择“Left Union”。 现在你会得到: Id Name Alias 1 A F 2 B G 2 B H 我不知道如何将多个“Set2”行放入一行 You could perform ...
-
更新: 用类似的东西循环遍历数组并不困难 foreach($messages as $k => $m){ if(strtotime($m['Message']['updatedate']) > strtotime($m['Message']['createdate'])){ $messages[$k]['Message']['NewDate'] = $m['Message']['updatedate']; }else{ $messages[$k]['Messa ...
-
也许你可以从OrgToMember实例开始并从那一点访问Org。 您甚至不必再访问会员,因为您需要知道的是它的pk,我猜你知道这一点。 otms = OrgToMember.objects.filter(member__pk=2) for otm in otms: org_name = otm.org.org_name balance = otm.balance notifications = otm.notifications print org_name, balance ...
-
我的问题的解决方案实际上是在这里找到的答案 。 基本上将beforeMarshal调用添加到我的[mymodel] Table.php中,一旦我正确地执行了此操作,有效的日期时间格式就被添加到我的数据库字段中。 抱歉有些重复的问题。 Solution for my issue was actually in the answer found here. Basically adding the beforeMarshal call into my [mymodel]Table.php and once I ...
-
您基本上要求的是最小集合覆盖,已知为NP Complete的问题。 幸运的是,这并不意味着您无法解决此类小案例。 您还可以通过贪婪算法获得O(logn)近似值。 如果你的枚举值没有特定的结构,那么对于一般的精确解,你将无法比蛮力做得更好。 如果您知道您的枚举具有特定的结构,那么通常可以通过图形分区或CSP +回溯等方式获得更好的结果。 What you are basically asking for is minimum set cover, a problem known to be NP Comple ...