我正在尝试向MongoDB添加授权.
我正在使用MongoDB 2.6.1在Linux上完成所有这些工作.
我的mongod.conf文件采用旧的兼容性格式
(这是安装时的方式).
1)我创建了管理员用户,如(3)中所述
http://docs.mongodb.org/manual/tutorial/add-user-administrator/
2)然后我通过取消注释这一行来编辑mongod.conf
auth = true
3)最后我重新启动了mongod服务,我尝试登录:
/usr/bin/mongo localhost:27017/admin -u sa -p pwd
4)我可以连接,但它在连接时说出来.
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
Run Code Online (Sandbox Code Playgroud)
5)现在看来sa我创建的这个用户根本就没有权限.
root@test02:~# mc
MongoDB shell version: 2.6.1
connecting to: localhost:27017/admin
Welcome to the MongoDB shell!
The current …Run Code Online (Sandbox Code Playgroud) 我在开发的自定义Android视图中收到此警告(来自问题标题).
为什么我会收到警告?它背后的逻辑是什么,即为什么在
覆盖performClick时也会覆盖它onTouchEvent?
我想我已经在JavaScript中遇到了这种经典情况.
通常程序员会希望下面的代码可以打印"Peter","Paul","Mary".
但事实并非如此.谁能解释为什么它在Java中以这种方式工作?
这个Java 8代码编译好并打印3次"Mary".
我想这是一个问题,它是如何在内心深处实施的,
但是......这不是表明底层实施的错误吗?
import java.util.List;
import java.util.ArrayList;
public class Test008 {
public static void main(String[] args) {
String[] names = { "Peter", "Paul", "Mary" };
List<Runnable> runners = new ArrayList<>();
int[] ind = {0};
for (int i = 0; i < names.length; i++){
ind[0] = i;
runners.add(() -> System.out.println(names[ind[0]]));
}
for (int k=0; k<runners.size(); k++){
runners.get(k).run();
}
}
}
Run Code Online (Sandbox Code Playgroud)
相反,如果我使用增强的for循环(同时添加Runnables),则捕获正确的(即所有不同的)值.
for (String name : names){
runners.add(() -> System.out.println(name));
}
Run Code Online (Sandbox Code Playgroud)
最后,如果我使用经典的for循环(同时添加Runnables),那么我会得到一个编译错误(这很有意义,因为变量i不是最终的或有效的最终).
for (int i = …Run Code Online (Sandbox Code Playgroud) 我在 Windows 10 上使用 conda 安装了 psycopg2。
https://anaconda.org/anaconda/psycopg2
我是在一个干净的新 conda 环境(名为 wr)中完成的。
然后我尝试运行此示例应用程序,但收到此错误(见下文)。我不知道我可能做错了什么,因为这一切都很简单,而且我做得很干净。
有什么想法如何解决这个问题吗?
import psycopg2
try:
connection = psycopg2.connect(user = "***",
password = "***",
host = "***",
port = "5432",
database = "***")
cursor = connection.cursor()
# Print PostgreSQL Connection properties
print ( connection.get_dsn_parameters(),"\n")
# Print PostgreSQL version
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record,"\n")
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close() …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此脚本将生成的列添加到现有表中。
alter table Asset_Store add column
md5_hash VARCHAR(100) GENERATED ALWAYS AS
(CAST(UPPER(
case
when OR_ID is not null then MD5(cast(OR_ID as varchar(100)))
when Asset_ID is not null then MD5(Asset_ID)
else null
end
) as VARCHAR(100)))
STORED
;
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
SQL Error [42601]: ERROR: syntax error at or near "("
Position: 88
ERROR: syntax error at or near "("
Position: 88
ERROR: syntax error at or near "("
Position: 88
Run Code Online (Sandbox Code Playgroud)
有什么问题吗?我不明白。
在我的 Asset_Store 表的架构中,列
OR_ID 为int,Asset_ID 为varchar(100)。
我猜它需要稍微不同的语法......但是正确的语法是什么?
为什么第一个回归null,而第二个回归mail.yahoo.com?
这不奇怪吗?如果没有,这种行为背后的逻辑是什么?
下划线是罪魁祸首吗?为什么?
public static void main(String[] args) throws Exception {
java.net.URI uri = new java.net.URI("http://broken_arrow.huntingtonhelps.com");
String host = uri.getHost();
System.out.println("Host = [" + host + "].");
uri = new java.net.URI("http://mail.yahoo.com");
host = uri.getHost();
System.out.println("Host = [" + host + "].");
}
Run Code Online (Sandbox Code Playgroud) 我在看这个方法: FileSystem.listFiles(Path f, boolean recursive)
列出给定路径中文件的状态和块位置.如果路径是目录,如果recursive为false,则返回目录中的文件; 如果recursive为true,则返回以该路径为根的子树中的文件.如果路径是文件,则返回文件的状态和块位置.
我正在测试该方法,它似乎没有返回给定目录的子目录.这是设计(似乎虽然它的java.io对应物不起作用)?如果这个限制是设计的,那么如果我想列出所有子目录,还有什么选择呢?
另一种方法FileSystem.listStatus(Path f)也不是返回子目录的状态.我错过了什么?
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class Test001 {
public static void main(String[] args) {
Date dt = new Date();
LocalDateTime localDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS zzz").withZone(ZoneId.of("America/New_York"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS zzz");
System.out.println(formatter.format(localDateTime));
System.out.println(sdf.format(dt));
}
}
Run Code Online (Sandbox Code Playgroud)
2016-04-19 11:25:34.917 ET
2016-04-19 11:25:34.637 EDT
Run Code Online (Sandbox Code Playgroud)
我的笔记本电脑的时区是"美国/纽约"(即东部时间美国/加拿大).
我想知道如何使用"EDT"代替"ET" DateTimeFormatter.
我也想知道:为什么在解析/格式模式方面DateTimeFormatter不兼容SimpleDataFormat(因为这个例子表明它们不兼容).
我来自 Java,其中 Exceptions 和 Errors 是完全不同的东西,它们都源自于一个叫做Throwable. 在 Java 中,您通常不应该尝试捕获错误。
在 Python 中,虽然区别似乎很模糊。
到目前为止,在阅读了一些文档并检查了层次结构后,我有以下问题:
存在语法错误,这当然会导致您的程序根本无法启动。对?
“在执行过程中检测到的错误称为异常,并不是无条件致命的”(根据教程)。这里的“致命”是什么意思?此外,一些像 AttributeError 这样的对象(根据上面的定义)实际上是异常,即使它们的名称中包含 Error,这个结论是否正确?
一些类派生自 Exception 但在其名称中包含 Error。这不是令人困惑吗?但即便如此,这也意味着名称中的 Error 并没有什么特别之处,它仍然是一个 Exception。或不... ?
“所有内置的非系统退出异常都源自 [Exception]”(引自此处)
那么哪些是系统退出异常,哪些不是?目前还不清楚。所有用户定义的异常也应该从 Exception 派生。所以基本上作为初学者,除了 Exception 之外,我还需要担心其他任何事情吗?好像没有。
警告也源自异常。那么警告是致命的还是系统退出的,或者这些都不是?
AssertionError 在哪里适合所有这些?它是致命的还是系统退出?
如何知道或指定某个 Exception 类表示致命的或系统退出的异常?
我可以自己定义,例如:
@FunctionalInterface
interface EmptyEmptyFunction {
void apply();
}
Run Code Online (Sandbox Code Playgroud)
然后按如下方式使用它:
EmptyEmptyFunction m = () -> {System.out.println("Hello World - Java 8!");};
m.apply();
Run Code Online (Sandbox Code Playgroud)
我的问题是:JDK中是否有内置类型
EmptyEmptyFunction,或者我必须自己定义EmptyEmptyFunction
(就像我已经做过的那样)?
这里有许多功能接口
http://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
但我似乎找不到一个
与我的"签名" 完全相同的人EmptyEmptyFunction.