我在从ResultSet对象获取数据时遇到问题.这是我的代码:
String sql = "SELECT type FROM node WHERE nid = ?";
PreparedStatement prep = conn.prepareStatement(sql);
int meetNID = Integer.parseInt(node.get(BoutField.field_meet_nid));
prep.setInt(1, meetNID);
ResultSet result = prep.executeQuery();
result.beforeFirst();
String foundType = result.getString(1);
if (! foundType.equals("meet")) {
throw new IllegalArgumentException(String.format("Node %d must be of type 'meet', but was %s", meetNID, foundType));
}
Run Code Online (Sandbox Code Playgroud)
错误跟踪:
Exception in thread "main" java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1072)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:986)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:981)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5656)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5576)
at nth.cumf3.nodeImport.Validator.validate(Validator.java:43)
at …Run Code Online (Sandbox Code Playgroud) 如果我有嵌套循环,我想立刻打破所有这些循环怎么办?
while (true) {
// ...
while (shouldCont) {
// ...
while (shouldGo) {
// ...
if (timeToStop) {
break; // Break out of everything?
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在PHP中,break接受一个参数来确定要突破的循环数.可以在C#中完成这样的事情吗?
有什么可怕的东西,比如goto?
// In the innermost loop
goto BREAK
// ...
BREAK: break; break; break;
Run Code Online (Sandbox Code Playgroud) 我有一个节点/角度项目,它使用npm进行后端依赖管理,并使用bower进行前端依赖管理.我想使用grunt任务来执行两个安装命令.我一直无法弄清楚如何做到这一点.
我尝试使用exec,但实际上并没有安装任何东西.
module.exports = function(grunt) {
grunt.registerTask('install', 'install the backend and frontend dependencies', function() {
// adapted from http://www.dzone.com/snippets/execute-unix-command-nodejs
var exec = require('child_process').exec,
sys = require('sys');
function puts(error, stdout, stderr) { console.log(stdout); sys.puts(stdout) }
// assuming this command is run from the root of the repo
exec('bower install', {cwd: './frontend'}, puts);
});
};
Run Code Online (Sandbox Code Playgroud)
当我cd进入前端,打开node,并从控制台运行此代码,这工作正常.我在咕噜咕噜的任务中做错了什么?
(我也尝试使用bower和npm API,但也无法使用.)
它似乎是某些类型的等效比较,但不是字符串.
# 3 != 3;;
- : bool = false
# 3 != 2;;
- : bool = true
Run Code Online (Sandbox Code Playgroud)
这是预期的.
# "odp" = "odp";;
- : bool = true
# "odp" != "odp";;
- : bool = true
# "odp" <> "odp";;
- : bool = false
Run Code Online (Sandbox Code Playgroud)
为什么"odp" != "odp"评估true?它到底在做什么?它不应该生成类型错误?
DATABASES = {
# 'default': {
# 'ENGINE': 'postgresql_psycopg2',
# ...
# }
# for unit tests
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
}
Run Code Online (Sandbox Code Playgroud)
我有两个数据库:一个我想用于单元测试,一个用于其他一切.是否可以在Django 1.2.4中配置它?
(我问的原因是因为使用postgresql我收到以下错误:
foo@bar:~/path/$ python manage.py test
Creating test database 'default'...
Got an error creating the test database: permission denied to create database
Type 'yes' if you would like to try deleting the test database 'test_baz', or 'no' to cancel: yes
Destroying old test database...
Got an error recreating the test database: database "test_baz" does …Run Code Online (Sandbox Code Playgroud) 我System.out.println()和System.err.println()电话没有按照我制作的顺序打印到控制台.
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.println("out");
System.err.println("err");
}
}
Run Code Online (Sandbox Code Playgroud)
这会产生:
out
out
out
out
out
err
err
err
err
err
Run Code Online (Sandbox Code Playgroud)
而不是交替out和err.为什么是这样?
我很难找到有关如何编写自定义小部件的文档.
我的问题是:
谢谢.
我希望在Eclipse中的 Java应用程序中找到瓶颈.我认为这可能有用:
http://www.eclipse.org/projects/project_summary.php?projectid=tptp.performance
还有其他好的插件吗?
编辑好了,它不一定是Eclipse插件.但这会很好.而且,我对速度最感兴趣.
有时,我会运行一个意外包含无限循环或其他东西的程序.Eclipse将让我继续编辑程序,但速度超慢.我怎么能阻止它?(我想重新启动JVM吗?)重启eclipse本身总是有效,但这会破坏我的工作流程.
我正在尝试使用Java中的SVMLight,在此页面上使用JNI包装器:
static {
System.loadLibrary("lib/JNI_SVM-light-6.01/lib/svmlight");
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
... lib\JNI_SVM-light-6.01\lib\svmlight.dll:无法在AMD 64位平台上加载IA 32位.dll
我可以通过重新编译64位的.dll来解决这个问题吗?我该怎么做呢?我可以使用其他一些解决方法吗?SVMLight使C源代码可用.