我已将我的数据库导出到CSV文件,时间戳现在如下所示:
1384204028
例如,如何将其转换为典型格式2013-01-19 03:14:07?
我尝试用Java读取JSON文件.代码是:
public static void main(String[] args) throws Exception {
InputStream is = new FileInputStream("j.txt");
String jsonTxt = IOUtils.toString( is );
JSONObject json = (JSONObject) JSONSerializer.toJSON( jsonTxt );
JSONObject routes = json.getJSONObject("routes");
JSONObject legs = routes.getJSONObject("legs");
JSONObject distance = legs.getJSONObject("distance");
String dist = distance.getString("text");
}
Run Code Online (Sandbox Code Playgroud)
该行JSONObject json = (JSONObject) JSONSerializer.toJSON( jsonTxt );出错:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at …Run Code Online (Sandbox Code Playgroud) 我必须使用MultiMap实现Priority Queue.我使用Google Collections中的MultiMap.以下代码创建了一个MultiMap,并在其中添加了一些元素.
Multimap<Integer, String> multimap = HashMultimap.create();
multimap.put(5,"example");
multimap.put(1,"is");
multimap.put(1,"this");
multimap.put(4,"some");
Run Code Online (Sandbox Code Playgroud)
现在我的问题是如何编写pop方法?
我认为应该有一个for循环,它应该迭代通过MultiMap.
最低的键应该是最高优先级,所以在C++中我会设置一个指向第一个元素的指针并递增它.怎么用Java做?
我可以这样做吗?这会有用吗?
double *vec_subtraction (char *a, char *b, int n)
{
double *result;
int i;
for(i=0; i<n; i++)
result[i] = a[i]-b[i];
return result;
}
Run Code Online (Sandbox Code Playgroud)
然后在主要:
double *vec=vec_substraction(a, b, n);
for(i=1; i<n; i++)
printf("%d", vec[i]);
Run Code Online (Sandbox Code Playgroud)
a和b是具有相同元素数的向量,n是元素数.
我有功能:
char *zap(char *ar) {
char pie[100] = "INSERT INTO test (nazwa, liczba) VALUES ('nowy wpis', '";
char dru[] = "' )";
strcat(pie, ar);
strcat(pie, dru);
return pie;
}
Run Code Online (Sandbox Code Playgroud)
主要有:
printf("%s", zap( argv[1] ) );
Run Code Online (Sandbox Code Playgroud)
编译时我收到警告:
test.c: In function ‘zap’:
test.c:17: warning: function returns address of local variable
Run Code Online (Sandbox Code Playgroud)
我该如何归还char*?
我知道这是一个非常简单的问题,但我找不到解决方案.
我有一个主摆动对话框和其他摆动对话框.主对话框有一个按钮.如何在单击其他对话框打开的按钮后进行此操作?
编辑:
当我尝试这个:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
NewJDialog okno = new NewJDialog();
okno.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Cannot find symbol NewJDialog
Run Code Online (Sandbox Code Playgroud)
第二个窗口名为NewJDialog ...
我有一个从多行文本框复制的字符串.我正在寻找一种方法来替换包含特定短语的整行.例如,字符串如下所示:
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Suspendisse egestas.
Run Code Online (Sandbox Code Playgroud)
所以我想找到一个方法elit用新行替换包含例如短语的整行,enim vehicula pellentesque.所以resoult将是:
Lorem ipsum dolor sit amet,
enim vehicula pellentesque.
Suspendisse egestas.
Run Code Online (Sandbox Code Playgroud)
有快速的方法吗?
谢谢
我正在尝试使用以下代码从数据库中选择数据:
//DATABASE
ResultSet rs;
String polecenie;
Statement st;
String[] subj;
public void polacz() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection pol=DriverManager.getConnection("jdbc:mysql://localhost:3306/testgenerator", "root", "pospaz");
st = pol.createStatement();
lblPolaczonoZBaza.setText("Po??czono z baz? danych testgenerator");
} catch (Exception ek) {
statusMessageLabel.setText("Can't connect to d: "+ek);
}
polecenie = "select * from subjects";
try {
rs = st.executeQuery(polecenie);
int i=0;
while (rs.next()){
subj[i] = rs.getString("name");
i++;
}
st.close();
} catch (Exception ek) {
statusMessageLabel.setText("Can't select data: "+ek);
}
}
Run Code Online (Sandbox Code Playgroud)
第二个捕获显示异常:
java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
我到处寻找,我找不到解决方案.我会感激任何帮助.
我正在尝试为每个i和j变量创建一个项目列表.我的代码是:
if (i == 0) {
if (j == 0) {
final CharSequence[] items = {"4:45", "5:00"}
} else if (j == 1) {
final CharSequence[] items = {"4:43", "4:58"}
} else if (j == 2) {
final CharSequence[] items = {"4:41", "4:56"}
} else {
final CharSequence[] items = {"4:38", "4:53"}
}
Run Code Online (Sandbox Code Playgroud)
...
new AlertDialog.Builder(this)
.setTitle("Hours")
.setItems(items,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface, int i) {
// getStation(i);
}
})
.show();
}
Run Code Online (Sandbox Code Playgroud)
我在行中收到错误.setItems(items,:
items cannot be …Run Code Online (Sandbox Code Playgroud) 我尝试从数据库中获取一些数据.连接方法确实有效,但我在获取任何数据表单DB时遇到问题:
SQLConnect s = new SQLConnect();
Connection c = s.getConnection();
Statement st = c.createStatement();
ResultSet rs = st.executeQuery("select * from produkty");
System.out.println(rs.getString(2));
Run Code Online (Sandbox Code Playgroud)
问题出在最后一行(当我评论它时,没有出现错误).错误信息:
Connected to database
Exception in thread "main" java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
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 antmedic.Main.main(Main.java:85)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助