package JDBC;import java.io.FileInputStream;import java.sql.*;import java.util.*;public class ExecuteDDL {private String driver;private String url;private String user;private String pass;Connection conn;Statement stmt;public void initParam(String paramFile) throws Exception{//使用Properties来加载属性文件Properties props=new Properties();props.load(new FileInputStream(paramFile));driver=props.getProperty("driver");url=props.getProperty("url");driver=props.getProperty("user");driver=props.getProperty("pass");}public void createTable(String sql) throws Exception{try{Class.forName(driver);conn=DriverManager.getConnection(url,user,pass);stmt=conn.createStatement();stmt.executeUpdate(sql);}finally//关闭数据库资源{if(stmt!=null){stmt.close();}if(conn!=null){conn.close();} }}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_increament primary key,"+"jdbc_name vachar(255),"+"jdbc_desc text);");System.out.println("--------------------建表成功-----------------"); }}报错在:props.load(new FileInputStream(paramFile)); ed.initParam("mysql.ini");
1 回答
倚天杖
TA贡献1828条经验 获得超3个赞
把props.load(new FileInputStream(paramFile))这句改成下面的:
InputStream in = getClass().getResourceAsStream(paramFile);
prop.load(in);
添加回答
举报
0/150
提交
取消