如何在java中使用可在任何计算机上运行的数据库 [英] how to use database in java that will work on any computer

查看:233
本文介绍了如何在java中使用可在任何计算机上运行的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我做了一堆java编程,但这是我第一次在应用程序中使用数据库。

So i have done a bunch of java programming but this is my first time using a database in an application.

我正在使用intellij和MySQL

I am using intellij and MySQL

现在我做了一个简单的应用来存储随机字。我使这个应用程序的计算机工作完美。我可以输入一个单词,单击保存,关闭程序,下次运行程序时,该单词将重新出现。

Now i made a simple application to store a random word. The computer i made this application on works perfectly. i can type a word, click save, close the program and the word will reappear the next time i run the program.

但是,在另一台计算机上使用此程序我会得到以下错误

However, using this program on another computer i will get the following error

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

如何让这个程序在任何其他计算机上运行

How do i make this program work on any other computer

这里有一些连接到数据库的代码

here is some of the code to connect to the database

public class ConnectionConfiguration {

public static Connection getConnection() {
    Connection connection = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/testDatabase", "root", "qwerty");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return connection;
}
}

谢谢!

推荐答案

- 将localhost改为IP(你的计算机有DB)
-将你的jar(mysql)提取到你的jar文件中(查看我的最后一个答案)你的主题)。

-Change "localhost" to IP (your computer got DB) -Extract your jar(mysql) to your jar file(check my last answer in your topic).

这篇关于如何在java中使用可在任何计算机上运行的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆