最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
JDBC连接MySQL数据库
时间:2022-07-02 18:20:25 编辑:袖梨 来源:一聚教程网
Step1:查找驱动程序
MySQL目前提供的java驱动程序为Connection/J,可以从MySQL官方网站下载,并找到mysql-connector-java-3.0.15-ga-bin.jar文件,此驱动程序为纯java驱动程序,不需做其他配置。
Step2:动态指定classpath
如果需要执行时动态指定classpath,就在执行时采用-cp方式。否则将上面的.jar文件加入到classpath环境变量中。
Step3:加载驱动程序
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading Mysql Driver!");
}
catch(Exception e)
{
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
Step4:设置连接的url
jdbc:mysql://localhost/databasename[?pa=va][&pa=va]
MySQL目前提供的java驱动程序为Connection/J,可以从MySQL官方网站下载,并找到mysql-connector-java-3.0.15-ga-bin.jar文件,此驱动程序为纯java驱动程序,不需做其他配置。
Step2:动态指定classpath
如果需要执行时动态指定classpath,就在执行时采用-cp方式。否则将上面的.jar文件加入到classpath环境变量中。
Step3:加载驱动程序
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading Mysql Driver!");
}
catch(Exception e)
{
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
Step4:设置连接的url
jdbc:mysql://localhost/databasename[?pa=va][&pa=va]
相关文章
- 阴阳师SSR孔雀明王强度介绍 05-20
- 明日方舟CW 05-20
- bitkeep官网下载app 05-20
- Ordi币安卓版官方登录版 05-20
- 《金铲铲之战》怒翼龙阵容装备搭配 05-20
- 欧易trust钱包安卓版2024 05-20