所以我已经弄清楚了我的错误,现在我只是在寻找一些关于究竟发生了什么的见解.我正在使用Apache Tomcat版本7.0.32.我正在使用本教程为JDBC设置池.在我的META-INF文件夹中,我创建了一个context.xml文件并将其放在那里.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource type="javax.sql.DataSource" name="jdbc/gmustudent"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/official"
username="root" password="root"
maxActive="100" maxIdle="20" minIdle="15" initialSize="15" maxWait="10000" />
</Context>
Run Code Online (Sandbox Code Playgroud)
我写这篇文章时遇到了这个错误
WARNING: Unexpected exception resolving reference
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:631)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:485)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:539)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:237)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1061)
at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:671)
at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:270)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at …
Run Code Online (Sandbox Code Playgroud) 我想要...
我认为这段代码可以工作,但由于某种原因它在第一个实例之后打破了循环,并且元素的类名永远不会改变.没有框架请.
function example()
{
var elementArray;
elementArray = document.getElementsByClassName("exampleClass");
for(var i = 0; i < elementArray.length; i++)
{
// PERFORM STUFF ON THE ELEMENT
elementArray[i].setAttribute("class", "exampleClassComplete");
alert(elementArray[i].className);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑(最终答复) - 这是最终产品以及我如何在我的网站中实施@ cHao的解决方案.目标是在页面上抓取各种时间戳并将其更改为时间.谢谢大家的帮助,我从这个问题中学到了很多东西.
function setAllTimeAgos()
{
var timestampArray = document.getElementsByClassName("timeAgo");
for(var i = (timestampArray.length - 1); i >= 0; i--)
{
timestampArray[i].innerHTML = getTimeAgo(timestampArray[i].innerHTML);
timestampArray[i].className = "timeAgoComplete";
}
}
Run Code Online (Sandbox Code Playgroud) 我想在一个批处理中发送两个不同的预处理语句.
目前我正在两个中这样做,你可以在评论的行中看到并且它有效,但这不是这里的主要目标.任何人都可以告诉我应该用什么来代替这些评论才能让这个东西起作用?
import java.lang.ClassNotFoundException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.DriverManager;
public class Main
{
public static void main(String[] args)
{
Connection connection = null;
PreparedStatement preparedStatementWithdraw = null;
PreparedStatement preparedStatementDeposit = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/youtube", "root", "root");
preparedStatementWithdraw = withdrawFromChecking(connection, preparedStatementWithdraw, new BigDecimal(100), 1);
preparedStatementDeposit = depositIntoSaving(connection, preparedStatementDeposit, new BigDecimal(300), 1);
//preparedStatementDeposit.executeBatch();
//preparedStatementWithdraw.executeBatch();
System.out.println("Account Modified!");
}
catch(ClassNotFoundException error)
{
System.out.println("Error: " + error.getMessage());
}
catch(SQLException error)
{
System.out.println("Error: " …
Run Code Online (Sandbox Code Playgroud) 我有一个提交的textarea ajax
使用onbeforeunload来警告用户,如果他们试图关闭浏览器,他们没有提交textarea.问题是我需要以某种方式清除ajax
提交成功中的onbeforeunload,以便onbeforeunload知道用户已成功提交表单.有没有办法用一行代码清除onbeforeunload,类似于clearTimeout或clearInterval?我将展示我目前拥有的onbeforeunload代码,即使我认为它不重要b/c我正在寻找一个不同的功能来清除它.没有框架请.谢谢.
函数调用
unsavedChangesWarning();
Run Code Online (Sandbox Code Playgroud)
Onbeforeunload功能
function unsavedChangesWarning(){
window.onbeforeunload = function(){
return 'If you close this page you will lose your stride update!';
};
}
Run Code Online (Sandbox Code Playgroud) 在我的web.xml文件中,我有这个
<!-- WELCOME FILE LIST -->
<welcome-file-list>
<welcome-file>/index</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)
哪个映射到此
<!-- SERVLET FOR THE HOME PAGE -->
<servlet>
<servlet-name>HomePageServlet</servlet-name>
<servlet-class>com.gmustudent.HomePageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HomePageServlet</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
当我把它放在地址栏中时,我得到了我的主页站点,servlet根据请求抓取了我的所有内容.
http://localhost:8086/gmustudent/index
Run Code Online (Sandbox Code Playgroud)
但是,这给了我一个404
http://localhost:8086/gmustudent/
Run Code Online (Sandbox Code Playgroud)
当没有明确说明索引时,为什么我的欢迎文件列表不会抓取欢迎文件servlet?
我是一个尝试javascript的java手,需要一些帮助.我在Mozilla教程中遇到了一个关于图像上传的惊人教程,需要一些帮助才能搞清楚.我目前正在处理拖放图像上传功能.每次我将图像拖到我的区域时,鼠标都会变为绿色,因此它会被激活.但是当我放手时,它应该向我发送一条警报,说明找到了一张图片.然而,它总是只提醒0.所以数组的大小是0.任何想法?谢谢参观.我尝试过但没有成功......
...
function toggleStrideMedia()
{
if(getDisplay("strideMediaWrapper") == "" || getDisplay("strideMediaWrapper") == "none")
{
show("strideMediaWrapper");
getElement("strideMediaDropZone").addEventListener("dragenter", dragenter, false);
getElement("strideMediaDropZone").addEventListener("dragover", dragover, false);
getElement("strideMediaDropZone").addEventListener("drop", drop, false);
}
else
{
hide("strideMediaWrapper");
}
}
function dragenter(e)
{
e.stopPropagation();
e.preventDefault();
}
function dragover(e)
{
e.stopPropagation();
e.preventDefault();
}
function drop(e)
{
e.stopPropagation();
e.preventDefault();
var dt = e.dataTransfer;
var files = dt.files;
// THIS SHOULD BE GIVING ME A ONE BUT IT ALWAYS GIVES ME A ZERO INSTEAD
alert(files.length);
handleFiles(files);
}
Run Code Online (Sandbox Code Playgroud)
.
更新 …
我想将友谊存储在数据库中.我的想法是,当user1成为user2的朋友时,我存储了这种友谊,这样我就可以获得所有用户的朋友,如果我需要的话.起初我以为我只是将他们的id存储在一个带有一个插入的表中,但是当我查询db时我想到了一些复杂性.
如果我有2个用户ID为10和20的用户,我应该在他们成为朋友时对数据库进行两次插入
ID USER1 USER2
1 10 20
2 20 10
Run Code Online (Sandbox Code Playgroud)
或者有没有办法查询数据库只有一个特定的用户朋友,如果我只做了一个这样的插入
ID USER1 USER2
1 10 20
Run Code Online (Sandbox Code Playgroud)
我知道第一种方式肯定可以给我我想要的东西,但我想知道这是不是很好的做法,如果有更好的选择.如果可以查询第二种方式来获得结果,我会像所有用户10的朋友一样寻找.
我是一个mac用户,从不使用IE.但昨天上班时我进入堆栈溢出并使用IE 9将其输入浏览器...
http://stackoverflow.com/questions/824349
Run Code Online (Sandbox Code Playgroud)
并且他们将URL替换为此而不刷新页面...
http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page
Run Code Online (Sandbox Code Playgroud)
我无法相信我所看到的.堆栈溢出如何能够利用模拟历史API在不支持它的浏览器上的替换状态的任何想法?
目前我有这个
<body>
...
</body>
Run Code Online (Sandbox Code Playgroud)
但是我想用javascript动态地将这个标签添加到我的页面(请不要jquery)
<body>
<div id="ajaxLoad"></div>
...
</body>
Run Code Online (Sandbox Code Playgroud)
所以新标签需要在body标签之后的第一件事.我怎样才能做到这一点?
假设我有一个显示博客帖子的网站.在这个网页上有一个评论部分,但它在页面加载时隐藏.但是,为用户显示注释计数,如果用户单击计数,则会调用ajax调用来加载所有注释.
通常我会做一些额外的编码来从页面中获取注释计数,然后将其发送到后端,这样我就可以限制我的查询.而不是这个......
SELECT * FROM comments INNER JOIN post WHERE post.id = 1
Run Code Online (Sandbox Code Playgroud)
我可以做这个...
SELECT * FROM comments INNER JOIN post WHERE post.id = 1 LIMIT 15
Run Code Online (Sandbox Code Playgroud)
所以现在我已经实现了这个我想知道,对于通过主键搜索故意告诉查询如何在主键上行的查询是否有任何好处?我做了一个带有和没有限制的SQL EXPLAIN,但它们是相同的.我主要担心的是我问这个问题的原因是b/c 我想确保查询不进行全表扫描,这就是为什么我总是养成添加限制的习惯.
如果我有这样的javascript对象......
window.object =
{
"Element1" :
{
"startDate" : "-1m",
"endDate" : "0d"
}
};
Run Code Online (Sandbox Code Playgroud)
我可以使用下面的代码提醒-1m ...
alert(object.Element1.startDate);
Run Code Online (Sandbox Code Playgroud)
但是,如果通过参数将Element1作为字符串提供给我,该怎么办?如果我必须使用变量,我怎么能得到相同的结果?像这样但不正确......
var elementId = this.id;
alert(object.elementId.startDate);
Run Code Online (Sandbox Code Playgroud) 所以我有一个非常大的字符串,它只会变大.它目前有1,539个字符,我希望将来可以再提出几个问题.因此,当我第一次构建字符串时,我按照旧方式创建了大约7个字符串对象并将它们连接起来.
但后来我想起了我的老师回答的问题,并决定将其切换并尝试使用字符串构建器.唯一的问题是我能在网上找到关于使用这个可读性的唯一真正的缺点,我认为可读性并不是说实话.
所以我的问题是构建一个对象,容纳超过1500个字符是一个好主意或一个坏主意.如果你在我的情况下你会使用字符串,字符串构建器或字符串缓冲区吗?请保存关于可读性的演讲.这只是我的代码,我是唯一一个阅读它的人,并不是那么困难,所以不要将它用作变量.谢谢!
StringBuilder builder = new StringBuilder(1600);
builder.append("SELECT stride.id AS link, user.userName, user.displayName, user.currentDefault, stride.content, stride.timestamp, stride.recipientView, \"stride\" as notType FROM user INNER JOIN stride ON user.id = stride.sourceUserId WHERE stride.recipientId = ? AND stride.sourceUserId != ? ");
builder.append(" UNION ALL ");
builder.append("SELECT stride.id AS link, user.userName, user.displayName, user.currentDefault, stride.content, strideLike.timestamp, strideLike.recipientView, \"strideLike\" as notType FROM user INNER JOIN strideLike ON strideLike.sourceUserId = user.id INNER JOIN stride ON stride.id = strideLike.strideId WHERE strideLike.recipientId = ? AND user.id != strideLike.recipientId …
Run Code Online (Sandbox Code Playgroud)