您好,以下代码,是关于java中executeUpdate的用法出现错误的?

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");

侃侃无极
浏览 169回答 1
1回答

倚天杖

把props.load(new FileInputStream(paramFile))这句改成下面的:InputStream in = getClass().getResourceAsStream(paramFile);prop.load(in);
打开App,查看更多内容
随时随地看视频慕课网APP