我是靠谱客的博主 明亮芝麻,这篇文章主要介绍eclipse怎么导入mysql?,现在分享给大家,希望可以做个参考。

在软件或是网站开发的过程中,数据库的连接是非常有必要的,不知道正在学习的你是否知道eclipse怎样连接mysql呢?不知道的朋友可以和我一起学习一下,不知道的朋友也可以来看看回顾一下,如有不对还望指正。

Eclipse中导入 mysql--conncetor --java--jars

在Eclipse中的工程项上右击,点Build Path->Configure Build Path-->Libraries-->Add External JARs(添加本地jars包)-->Apply

连接代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.sql.*; public class MysqlJdbc { public static void main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序 //Class.forName("org.gjt.mm.mysql.Driver"); System.out.println("Success loading Mysql Driver!"); } catch (Exception e) { System.out.print("Error loading Mysql Driver!"); e.printStackTrace(); } try { Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","123"); //连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码 System.out.println("Success connect Mysql server!"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from user"); //user 为你表的名称 while (rs.next()) { System.out.println(rs.getString("name")); } } catch (Exception e) { System.out.print("get data error!"); e.printStackTrace(); } } }
登录后复制

以上就是eclipse怎么导入mysql?的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是明亮芝麻最近收集整理的关于eclipse怎么导入mysql?的全部内容,更多相关eclipse怎么导入mysql内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(122)

评论列表共有 0 条评论

立即
投稿
返回
顶部