小编azu*_*rog的帖子

ClassNotFoundException:com.mysql.jdbc.jdbc2.optional.MysqlDataSource

我在我的项目中使用Hikari库进行MySQL连接.当我尝试运行该程序时,我得到一个ClassNotFoundException:com.mysql.jdbc.jdbc2.optional.MysqlDataSource错误.我想我必须在我的项目中包含mysql-connector库.

这是我的pom.xml

    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP-java6</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.18.1-GA</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.0.Beta3</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>GridControl</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Main-Class>net.thegridmc.control.GridControl</Main-Class>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <minimizeJar>true</minimizeJar>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <artifactSet>
                                <includes>
                                    <include>mysql:*</include>
                                    <include>org.slf4j:*</include>
                                    <include>com.zaxxer:*</include>
                                    <include>org.javassist:javassist</include>
                                    <include>io.netty:netty-all</include>
                                </includes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

jar已成功构建,但仍会出现错误.非常感谢任何帮助.谢谢.

java mysql jdbc maven

2
推荐指数
1
解决办法
9523
查看次数

任何人都可以告诉我为什么我的旧列表中只有新列表中应该存在的所有值.

  1. 我在tmp中存储一个列表,然后在列表中添加新值.
  2. 刷新时我将旧列表与新列表进行比较.
  3. 如果新列表有新条目然后生成通知,但每次我在旧列表中找到所有值.

    public void populateList(String result) {
        ArrayList<User> tmp;
        tmp = list;
        list.clear();
        try {
            JSONArray jsonArray = new JSONArray(result);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject json_data = jsonArray.getJSONObject(i);
                String NAME = json_data.getString(StaticMember.NAME);
                String STATUS = json_data.getString(StaticMember.STATUS);
                list.add(new User(NAME, STATUS));
            }
            ArrayList tmpN = list;
            compare(tmp, tmpN);
            CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, list);
            lv.setAdapter((customAdapter));
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void compare(ArrayList list_old, ArrayList list_new) {
        try {
            Iterator<User> iterator_old …
    Run Code Online (Sandbox Code Playgroud)

java android iterator arraylist

2
推荐指数
1
解决办法
69
查看次数

在Java中将String转换为Date会增加一些额外的时间

我在Java中将字符串转换为Date,但是我遇到了问题它在结果Date中添加了一些额外的分钟.

字符串具有以下格式"yyyy-MM-dd HH:mm:ss.sss"并且我已创建此函数:

public static Date parseISO8601(String date) {
    Date result = null;

    try {

        if (!TextUtils.isEmpty(date)) {
            SimpleDateFormat dateFormat = new SimpleDateFormat(
                    ISO8601_DATE_FORMAT);

            result = dateFormat.parse(date);
        }

    }
    catch (Exception ex){
        return null;
    }
    return result;
}

public static final String ISO8601_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.sss";
Run Code Online (Sandbox Code Playgroud)

当我使用此字符串 "2015-06-11 20:17:56.873"时,结果是"Thu Jun 11 20:31:33 CST 2015".我是Java的新编码,我已经阅读了很多帖子,但对我而言,一切似乎都很正常,我不知道为什么会发生这种情况.

一些想法?

java date

2
推荐指数
1
解决办法
104
查看次数

java队列接口

我正在查看 java 队列,我坚持这一行“队列实现通常不定义 equals 和 hashCode 方法的基于元素的版本,而是从 Object 继承基于身份的版本。

1.需要以上文字的完整意思。
2.什么是equals和hashcode的基于元素的版本——它指的是什么?
3.基于身份的版本——这是什么意思?
4. 版本是属于类还是对象/谁的版本以及它将在哪里?

网址:https : //docs.oracle.com/javase/tutorial/collections/interfaces/queue.html

java queue interface

2
推荐指数
1
解决办法
455
查看次数

Java:运算符和类型转换

long value = 0x88888888 ;
int i = (int) (value & 0xff);
Run Code Online (Sandbox Code Playgroud)

如何进行上述表达评估?是吗

int i = (int)value & (int)0xff ;
Run Code Online (Sandbox Code Playgroud)

或者首先评估按位和操作?我很困惑: - |

java bit-manipulation operators bitwise-operators typecast-operator

1
推荐指数
1
解决办法
82
查看次数

在Java中将数组的所有元素移回一个元素

我正在编写一个代码,将数组的所有元素移回一个,并将最后一个元素移动到数组的前面.

我非常希望我的程序能够这样做:

int[] array = new int[] {1, 2, 3};
// do something such that array will become {3, 1, 2}
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

int[] array = new int[3];


for(int i = 0; i < array.length; i++)
{
  array[0] = 1;
  array[1] = 2;
  array[2] = 3;
  int last = array[array.length-1];
  array[i] = array[i+1];
  array[0] = last;

  System.out.println(array[i]);
}
Run Code Online (Sandbox Code Playgroud)

我认为为数组添加1到"i",并将数组的最后一个元素存储在"last"中并将其分配给array [0]就可以了,但我只是得到了{3,3}输出"java.lang.ArrayIndexOutOfBoundsException:3".

java arrays

1
推荐指数
1
解决办法
2404
查看次数

我的ArrayList中的.add有什么问题?

我目前正在开发一个简单的java游戏,代表DOS游戏Gorillas.bas.我正在创建一个arraylist来存储各个建筑物进行碰撞检查等等,但是无论我怎么做,Eclipse都会给我一个错误.这是我为arraylist所得到的.

ArrayList<Rectangle> Buildings = new ArrayList<Rectangle>();
Point build1 = new Point(75,30);
Rectangle building1 = new Rectangle(build1, BUILDING_WIDTH, 150);
Buildings.add(Rectangle building1);
Run Code Online (Sandbox Code Playgroud)

错误在于.add()方法,它告诉我该方法需要一个正文而不是一个分号.这是什么意思?日食不承认.add()吗?

编辑:请求周围的一些代码; 似乎没有任何语法错误.

public double bananaX = 85; 
public double bananaY = 292;
public double bananaDX = 1; 
public double bananaDY = 1;
public double power = 0;
public double direction = 0;
public double rise;
public double run;
Point start = new Point(0,0);
Point finish = new Point(0,0);`

ArrayList<Rectangle> buildings = new ArrayList<Rectangle>(); …
Run Code Online (Sandbox Code Playgroud)

java eclipse arraylist

1
推荐指数
1
解决办法
809
查看次数

误解主要方法/"public static void main(String [] args)"

我有一个编写带有构造函数的类的赋值+各种方法将值返回给主类.

由于错误,我的代码永远无法正确编译:无法找到简单或非法的表达式启动.

我相信我从根本上误解了如何构造一个构造函数,究竟主要方法是什么,以及一个类如何调用另一个类.

分配:

假设您获得了以下Driver类,其中包含一个main方法:

public class Driver {   
    public static void main(String[] args)   {
        double distance = 400.48;
        double fuel = 21.4;
        AutoTrip myTrip = new AutoTrip(distance, fuel);
        System.out.print("My car traveled " + myTrip.getDistance() + " miles");
        System.out.println("on " + myTrip.getFuel() + " gallons of gasoline.");
        double mileage = myTrip.getMPG(); // get miles per gallon
        System.out.println("My mileage was " + mileage + ".");  
    } 
}
Run Code Online (Sandbox Code Playgroud)

*现在假设执行主要产生以下输出:我的汽车在21.4加仑汽油上行驶了400.48英里.

我的里程是18.714018691588787.

实现AutoTrip类,以便生成指示的输出.*

我的代码:

public class AutoTrip { 
    public AutoTrip(double distance, double fuel){
         this.distance …
Run Code Online (Sandbox Code Playgroud)

java constructor

1
推荐指数
1
解决办法
801
查看次数

JAVA的帮助,我似乎无法找到错误

我是java的初学者,我一直在玩数组,但我无法理解什么是错误的.

这是班级:

public class StringArrayUtil {

        public static void print(String [] sArray){
            for(int i = 0; i<sArray.length; i++){
                if(sArray[i] !=null){
                    System.out.println("Indice: "+i+ " String: "+sArray[i] + "\t");
                }
            }
        }

        public static int indexOf(String [] sArray, String sSearch, int s){
            for(int i = s; i < sArray.length; i++){
                if(sArray[i] != null && sSearch != null && sSearch.equals(sArray[i])){
                    return i;
                }
            }   
            return -1;
        }

        public static int indexOf(String [] sArray, String sSearch){
            return indexOf(sArray, sSearch, 0);

        }

        public static int …
Run Code Online (Sandbox Code Playgroud)

java arrays

0
推荐指数
1
解决办法
95
查看次数

JAVA,我应该使用"导入"吗?

代码1

public class launcher{
    public static void main(String[] args){
        javax.swing.JOptionPane.showMessageDialog(null,"HelloWorld");
    }
}
Run Code Online (Sandbox Code Playgroud)

码2

public class launcher{
    public static void main(String[] args){
        System.out.println("HelloWorld");
    }
}
Run Code Online (Sandbox Code Playgroud)

CODE3

public class launcher{
    public static void main(String[] args){
        int a = java.util.Random.nextInt(10);
    }
}
Run Code Online (Sandbox Code Playgroud)

码4

import java.util.Random;
public class launcher{
    public static void main(String[] args){
        Random rr = new Random();
        int num = rr.nextInt(10);
    }
}
Run Code Online (Sandbox Code Playgroud)

Code1和Code2在没有"import java.swing.JOptionPane"或"import System.out.println"的情况下运行良好

但是,Code3不能很好地工作.
我应该像Code4一样使用吗?

java import

0
推荐指数
1
解决办法
102
查看次数