exlipse怎么连接mysql服务器


利用exlipse连接mysql服务器,具体方法如下:

import java.sql.*;

publicclass mysqlJdbc {

publicstaticvoid 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","198876");

//连接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();

}

}

}


上一篇:ubuntu如何查看mysql的配置文件

下一篇:mysql数据库怎么设置自增属性


MySQL mysql服务器 exlipse
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器