eclipse写了个JDBC程序却找不到文件却抛出java.io.FileNotFoundException 文件找不到错误
2017-07-24 14:57
741 查看
package MysqlTest;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;
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();
//使用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);//获取数据库连接,使用Connection来创建一个Statment对象
Statement stmt=conn.createStatement())
{
stmt.executeUpdate(sql); //执行DDL,创建数据表
}
}
public static void main (String[] args) throws Exception
{
ExecuteDDL ed=new ExecuteDDL();
ed.initParam("my.ini");
ed.createTable("create table jdbc_test"+"(jdbc_id int auto_increment primary key,"+"jdbc_name varchar(255),"+"jdbc_desc text);");
System.out.println("----建表成功----");
}
}
Exception in thread "main" java.io.FileNotFoundException: my.ini (系统找不到指定的文件。)
后来发现my.ini文件一定要在工程目录下,查看工程目录方法:
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;
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();
//使用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);//获取数据库连接,使用Connection来创建一个Statment对象
Statement stmt=conn.createStatement())
{
stmt.executeUpdate(sql); //执行DDL,创建数据表
}
}
public static void main (String[] args) throws Exception
{
ExecuteDDL ed=new ExecuteDDL();
ed.initParam("my.ini");
ed.createTable("create table jdbc_test"+"(jdbc_id int auto_increment primary key,"+"jdbc_name varchar(255),"+"jdbc_desc text);");
System.out.println("----建表成功----");
}
}
Exception in thread "main" java.io.FileNotFoundException: my.ini (系统找不到指定的文件。)
后来发现my.ini文件一定要在工程目录下,查看工程目录方法:
相关文章推荐
- java.io.FileNotFoundException关于使用Intellij Idea时系统找不到指定文件的解决方案
- 关于写入文件缓存时报"java.io.FileNotFoundException open failed (is a director)"错误的解决方法
- 用jdbc中加载配置文件是出现java.io.FileNotFoundException的解决之道
- nested exception is java.io.FileNotFoundException: config.xml (系统找不到指定的文件。)
- java.io.FileNotFoundException问题,说是db.properties文件找不到,但是在webapps里存在的
- tomcat下载文件时,URL含有文字参数与空格参数出错(java.io.FileNotFoundException错误) 解决方法(转)
- Struts上传文件报java.io.FileNotFoundException错误
- Error:java.io.FileNotFoundException: 系统找不到指定的文件.
- 如何解决java.io.FileNotFoundException: mysql.ini (系统找不到指定的文件。)
- Android在文件操作时出现java.io.FileNotFoundException
- Log4J配置后, log4j:ERROR setFile(null,true) call failed. 报错:java.io.FileNotFoundException: /log/mytest2.log (系统找不到指定的路径。)
- java.io.FileNotFoundException: D:\Workspaces\MyEclipse 8.5\spring\applicationContext.xml (系统找不到指定的文
- 解决 System.IO.FileNotFoundException: 未能加载文件或程序集“Team.DLinqDAL”或它的某一个依赖项。系统找不到指定的文件。
- System.IO.FileNotFoundException: 未能加载文件或程序集
- keytool错误: java.io.FileNotFoundException: android.key (Permission denied)
- java.io.FileNotFoundException: D:\workspace\gbrm\WebRoot\空缺职位列表20140414093026.xls (系统找不到指定的路径。)
- keytool 错误: java.io.FileNotFoundException
- 错误java.io.FileNotFoundException: Source 'E:\Workspaces\MyEclipse 8.6\.metadata\.me_tcat\work\。。
- System.IO.FileNotFoundException: 未能加载文件或程序集 ,webservice 部署500错误
- android或者java 打开文件出现java.io.FileNotFoundException的解决方案