我试图min distance, min speed and max speed在我的查询结果中获取记录 .目前我的距离最短,但我面临着获得最小和最大速度的问题,我问自己是否有可能public int compareTo(BehaviourItem otherItem)在BehaviourItem课堂上添加另一种方法来达到这个目的但是我得到了错误 Duplicate method compareTo(BehaviourItem) in type BehaviourItem.
如何从BehaviourItem课堂上获得最低和最高速度?
码:
PreparedStatement prepared = con
.prepareStatement("SELECT speed, stop_distance from behaviour where mac = ? and stop_name = ?");
prepared.setString(1, macD);
prepared.setString(1, sto_nam);
ResultSet rsBehav = prepared.executeQuery();
List<BehaviourItem> behavList = new ArrayList<BehaviourItem>();
while (rsBehav.next()) {
int distance = rsBehav.getInt("stop_distance");
int speed = rsBehav.getInt("speed");
BehaviourItem behItem = new BehaviourItem(distance, speed);
behavList.add(behItem);
}
Collections.sort(behavList);
int minDistance …Run Code Online (Sandbox Code Playgroud) 我试图获取最小值的索引,但是当第一个元素的最小值为570(索引= 0)时,我收到此错误.我究竟做错了什么?
码:
//ArrayList of distanceList [570, 621, 716, 906, 1055, 1253, 1314, 1314]
ArrayList<Integer> distanceList = entry.getValue();
//min is 570
int min = Collections.min(distanceList);
int index = distanceList.get(min);
Run Code Online (Sandbox Code Playgroud)
错误:
threw exception [java.lang.IndexOutOfBoundsException: Index: 570, Size: 8] with root cause
java.lang.IndexOutOfBoundsException: Index: 570, Size: 8
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
Run Code Online (Sandbox Code Playgroud) 我试图检查数组中两个字符串的位置是否不同.例如,如果我有字符串apple和字符串,appendix那么两个字符串在i = 3的位置是不同的.
如何用Java检查?
码
//The first string is s.
char[] cArray = s.toCharArray();
// The seond string is root.edge.
char[] rootEdgeCharacter = root.edge.toCharArray();
for(int i=0; i<cArray.length; i++ ){
for(int j=0; j<rootEdgeCharacter.length; j++){
if(cArray[i]== rootEdgeCharacter[j]){
System.out.println("The String are different where i =" + i);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想将项目推送到github主页.因此,我正在尝试为github创建ssh-key来管理它,但我遇到的问题是git在错误的目录中/c/Users/user82/.ssh/id_rsa)而不是在项目目录中创建了ssh-key /desktop/dogs.
我怎么能告诉Git在项目目录中创建ssh-key /desktop/dogs而不是在这个目录中c/Users/user82呢?
user82@User MINGW64 ~/desktop/dogs (master)
$ ssh-keygen -t rsa -C "example@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/user82/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/user82/.ssh/id_rsa.
Your public key has been saved in /c/Users/user82/.ssh/id_rsa.pub.
Run Code Online (Sandbox Code Playgroud) 我试图将数据插入到我的停止表中,stops表和route正在创建的表,但程序无法将数据插入停止表,我收到此错误:
Unknown column '1' in 'field list'
Run Code Online (Sandbox Code Playgroud)
我感谢任何帮助.
stt.execute("CREATE TABLE IF NOT EXISTS routes"
+ "(route_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
+ "route INT(11) NOT NULL)" );
stt.execute("INSERT INTO routes(route) VALUES"
+ "(1),"
+ "(9)");
stt.execute("CREATE TABLE IF NOT EXISTS stops"
+ "(stop_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, "
+ " name varchar(30) NOT NULL, "
+ " lat double(10,6) NOT NULL, "
+ " longi double(10,6)NOT NULL,"
+ "route_id INT, FOREIGN KEY …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习Hibernate框架hibernate-release-5.1.0.Final.我已经包括了所有必需的罐子lib\required, lib\jpa, und lib\java8.请看下面的屏幕截图,我hb_student_tracker为Student类创建了一个数据库但是我收到的错误如下Caused by: java.lang.ClassNotFoundException: Could not load requested class : models.Category
我正在使用XAMPP控制面板的默认配置.用户名也是root密码.
hibernate.cfg.cml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hb_student_tracker</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<mapping class ="models.Category" />
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
学生
package com.tutorial.hibernate.demo.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="student")
public class Student {
@Id
@Column(name="id")
private int …Run Code Online (Sandbox Code Playgroud)