如何解决java.io.FileNotFoundException: mysql.ini (系统找不到指定的文件。)
2013-04-09 13:38
1571 查看
将mysal.ini文件放在java progect文件下,不要放在ExecuteDDL.java所在的文件加下!!!
import java.io.*; import java.sql.*; import java.util.*; public class ExecuteDDL { private String driver; private String url; private String user; private String pass; public void initParam(String paramFile) throws Exception { Properties props = new Properties(); props.load(new FileInputStream(paramFile)); driver = props.getProperty("driver"); url = props.getProperty("url"); user = props.getProperty("user"); pass = props.getProperty("pass"); } public void createTable(String sql) throws Exception { Class.forName(driver); try ( Connection conn = DriverManager.getConnection(url, user, pass); Statement stmt = conn.createStatement() ) { stmt.executeUpdate(sql); } } public static void main(String[] args) throws Exception { ExecuteDDL ed = new ExecuteDDL(); ed.initParam("mysql.ini"); ed.createTable("create table jdbc_test" + "(jdbc_id int auto_increment primary key," + "jdbc_name varchar(255)," + "jdbc_desc text);"); System.out.println("------建表成功-----"); } }
相关文章推荐
- java.io.FileNotFoundException关于使用Intellij Idea时系统找不到指定文件的解决方案
- Error:java.io.FileNotFoundException: 系统找不到指定的文件.
- nested exception is java.io.FileNotFoundException: config.xml (系统找不到指定的文件。)
- 解决 System.IO.FileNotFoundException: 未能加载文件或程序集“Team.DLinqDAL”或它的某一个依赖项。系统找不到指定的文件。
- 【已解决】Windows Service 问题System.IO.FileNotFoundException: 未能加载文件或程序集“file:///”或它 的某一个依赖项。系统找不到指定的文件。。
- Java properties | FileNotFoundException: properties (系统找不到指定的文件。)
- java.io.FileNotFoundException: .\xxx\xxx.png (系统找不到指定的路径。)
- 服务 在初始化安装时发生异常:System.IO.FileNotFoundException: "file:///D:\testService"未能加载文件或程序集。系统找不到指定文件。
- Java项目读取配置文件时,FileNotFoundException 系统找不到指定的文件,System.getProperty("user.dir")的理解
- log4j:ERROR setFile(null,true) call failed.java.io.FileNotFoundException: ..\logs\2010-1-19.log (系统找不到指定的路径。)
- java.io.FileNotFoundException: D:\workspace\gbrm\WebRoot\空缺职位列表20140414093026.xls (系统找不到指定的路径。)
- Android 混淆提示 java.io.FileNotFoundException: ...\proguard-rules\release\aapt_rules.txt (系统找不到指定的路径)
- java.io.FileNotFoundException: D:\Workspaces\MyEclipse 8.5\spring\applicationContext.xml (系统找不到指定的文
- Android 混淆提示 java.io.FileNotFoundException: ...\proguard-rules\release\aapt_rules.txt (系统找不到指定的路径)
- System.IO.FileNotFoundException:“未能加载文件或程序集“xxx”或它的某一个依赖项。系统找不到指定的文件。”
- Log4J配置后, log4j:ERROR setFile(null,true) call failed. 报错:java.io.FileNotFoundException: /log/mytest2.log (系统找不到指定的路径。)
- java.io.FileNotFoundException问题,说是db.properties文件找不到,但是在webapps里存在的
- 使用HttpURLConnection下载文件时出现 java.io.FileNotFoundException彻底解决办法
- 使用HttpURLConnection下载文件时出现 java.io.FileNotFoundException彻底解决办法
- 文件路径正确,报java.io.FileNotFoundException异常的原因及解决办法