连接到MySQL数据库 [英] Connect to a MySQL Database

查看:106
本文介绍了连接到MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


这个帖子非常类似于早期的帖子但我不想劫持一个帖子。


问题是这个。我在我的本地机器上有一个mysql数据库,我已经安装了Java和MySQL的驱动程序并使用Eclipse我可以连接到数据库并查看表等。


我想要什么do有一个定义如何连接到数据库的类,所以我一直在开发一个。我到目前为止的代码是:

Hi there,

This thread is very similar to an earlier thread but I didn''t want to hijack a thread.

The issue is this. I have a mysql database on my local machine, I have installed the driver for Java and MySQL and using Eclipse I can connect to the database and see the tables etc.

What I want to do is have a class that defines how to connect to a database and so I have been working on developing one. The code I have so far is:

展开 | 选择 | Wrap | 行号

推荐答案

这里是对代码的轻微更新和输出:

Here''s a slight update to the code and the output:

展开 | 选择 | Wrap | 行号


1。)如果你使用e.printStackTrace(),您将获得完整的异常跟踪。

2.)该类是您安装驱动程序的项目的一部分吗?
1.) If you use e.printStackTrace() you will get the full exception trace.
2.) Is that class part of the project which you have installed the driver for?


关于printStackTrace的提示。我按照建议使用它(对于捕获部分e和e1),我在控制台中得到以下输出:
Thatnks for tip about printStackTrace. I used that as suggested (to both the catch sections e and e1) and I get the following output in the console:
展开 | 选择 | 换行 | 行号


这篇关于连接到MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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