我正在研究现有的基于Java EE的应用程序.这具有以下连接数据库的方法:
public static java.sql.Connection connectionToDataBase(String jndiName,boolean flag)throws Exception
{
DataSource ds =(javax.sql.DataSource) initCtx.lookup(jndiName);
return ds.getConnection();
} catch (NamingException ne) {
throw ne;
} finally {
try {
if (initCtx != null)
initCtx.close();
} catch (NamingException ne) {
throw ne;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是使用静态方法连接数据库是否正确?
我正在使用Ubuntu 12.我想在我的Ubuntu Machine主目录中搜索"SymbolSetThree"这个词.
为此我用过
grep "SymbolSetThree" /home
Run Code Online (Sandbox Code Playgroud)
它只显示为grep:/ home:是一个目录
请告诉我如何在Linux中搜索所有文件中的特定单词?
这是我试过的
sai@sai-Aspire-4720Z:/$ grep "SymbolSetThree" /home
grep: /home: Is a directory
Run Code Online (Sandbox Code Playgroud) 我使用的是 Google Chrome 版本 24
我正在查看一个网站,其中数据通过 websocket 调用获取到前端。
我的问题是,“是否可以从浏览器查看 Web 套接字响应?” 有这样的工具吗?
请告诉我,提前谢谢。
javascript browser google-chrome websocket google-chrome-devtools
我的集合中有一个名为people的复合索引,如下所示
db.people.getIndexes()
[
{
"name" : "_id_",
"ns" : "at.people",
"key" : {
"_id" : 1
}
},
{
"_id" : ObjectId("521dd652a185d3defe301983"),
"ns" : "at.people",
"key" : {
"personname" : 1,
"email" : 1,
"sex" : 1,
"course" : 1
},
"name" : "personname_1_email_1_sex_1_course_1",
"unique" : false
}
]
Run Code Online (Sandbox Code Playgroud)
我试图以这种方式放弃这个索引
db.people.dropIndex({"personname_1_email_1_sex_1_course_1": 1})
Run Code Online (Sandbox Code Playgroud)
但我收到错误消息
{"errmsg":"找不到索引","ok":0}
我还尝试按名称删除索引
db.people.dropIndex( { "name" : "personname_1_email_1_sex_1_course_1" } )
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用下面的命令一次性删除集合上的索引
db.people.dropIndexes()
Run Code Online (Sandbox Code Playgroud)
请让我知道如何解决这个问题?
我正在尝试使用PhoneGap在Android中开发应用程序.
这是我的代码
package com.example.streat;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("SOMESTRING", "I am into pGAP");
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.streat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.streat.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<activity
android:name="org.apache.cordova.DroidGap"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<intent-filter></intent-filter>
</activity>
</manifest>
Run Code Online (Sandbox Code Playgroud)
当在Logcat内部进行监控时,我最终会收到此异常 …
我不希望缓存HTML5页面,所以我在HTML文件下使用这些标签。
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="js/jquery-1.10.2.min.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
当我通过http://validator.w3.org/check验证了这些内容时,
俗话说
元素元数据上的属性http-equiv的错误值缓存控制。
<meta http-equiv="cache-control" content="max-age=0" />
Run Code Online (Sandbox Code Playgroud)
元素元数据上的属性http-equiv的错误值缓存控制。
<meta http-equiv="cache-control" content="no-cache" />
Run Code Online (Sandbox Code Playgroud)
元素元数据上的属性http-equiv的错误值过期。
<meta http-equiv="expires" content="0" />
Run Code Online (Sandbox Code Playgroud)
元素元数据上的属性http-equiv的错误值过期。
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
Run Code Online (Sandbox Code Playgroud)
元素meta上的属性http-equiv的错误值编译指示。
<meta http-equiv="pragma" content="no-cache" />
Run Code Online (Sandbox Code Playgroud)
您能否让我知道如何解决这个问题?
class Semaphore {
private int count=100;
public Semaphore(int n) {
this.count = n;
}
public synchronized void acquire() {
while(count == 0) {
try {
wait();
} catch (InterruptedException e) {
//keep trying
}
}
count--;
}
public synchronized void release() {
count++;
notify(); //alert a thread that's blocking on this semaphore
}
}
Run Code Online (Sandbox Code Playgroud)
目前我支持100个用户.如果一个请求来自于JSP(客户端),并通过这个类去,将线程(从JSP请求)wait和notify自动?
我在我的Web应用程序中使用Jetty Websockets.
当我试图重定向到注销jsp时,我收到此错误
oejs.ServletHandler:/test
java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1069)
at javax.servlet.ServletResponseWrapper.resetBuffer(ServletResponseWrapper.java:232)
at org.eclipse.jetty.http.gzip.GzipResponseWrapper.resetBuffer(GzipResponseWrapper.java:273)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:199)
at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:98)
Run Code Online (Sandbox Code Playgroud)
这是我重定向的方式
RequestDispatcher rd = request.getRequestDispatcher("logoff.jsp");
rd.forward(request, response);
Run Code Online (Sandbox Code Playgroud)
这个错误不可重现,但你可以告诉我什么时候可能发生?
我有一个如下所示的集合:
db.testdata.save(
{
"Indicator": "One",
"secs": [
{
"when": "2013-03-16",
"num": 16,
"choices": [
{
"size": "10",
"mult": "10"
},
{
"size": "10",
"mult": "10"
}
]
},
{
"when": "2013-03-22",
"num": 24,
"choices": [
{
"size": "100",
"mult": "100"
},
{
"size": "100",
"mult": "100"
}
]
}
]
})
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用自定义对象检索它,如下所示:
public class Test {
public static void main(String args[]) throws UnknownHostException {
Mongo mongo = new Mongo();
DB db = mongo.getDB("at");
DBCollection testdata = db.getCollection("testdata");
BasicDBObject query = …Run Code Online (Sandbox Code Playgroud) 我以这种格式记录了一个日期
2014-12-09 02:18:38
Run Code Online (Sandbox Code Playgroud)
我需要将其转换为
09-12-2014 02:18:38
Run Code Online (Sandbox Code Playgroud)
我尝试过这种方式转换
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class TestDate {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-YYYY HH:mm:ss");
String input = "2014-12-09 02:18:38";
String strDate = sdf.format(input);
System.out.println(strDate);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我在运行时遇到了这个异常
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:301)
at java.text.Format.format(Format.java:157)
at TestDate.main(TestDate.java:15)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题.