本帖最后由 李红亮 于 2013-10-17 08:34 编辑
大家好,我最近在学mysql,写了个小程序,但是一直提示有错,我看了很多遍了,就是看不出怎么就错了,代码如下:
import java.sql.*;
import java.io.*;
import java.util.*;
public class ExecuteDML
{
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 int insertDate(String sql)throws Exception
{
Class.forName(driver);
try(Connection conn = DriverManager.getConnection(url , user , pass);
Statement stmt = conn.createStatement())
{
return stmt.executeUpdate(sql);
}
}
public static void main(String[] args)throws Exception
{
ExecuteDML ed = new ExecuteDML();
ed.initParam("E:\\疯狂java第二版光盘\\codes\\13\\13.4\\mysql.ini");
int result = ed.insertDate("insert into jdbc_test(jdbc_name,jdbc_desc)"
+ "select s.student_name , t.teacher_name "
+ "from student_table s , teacher_table t "
+ "where s.java_teacher = t.teacher_id;");
System.out.println("--系统中共有" + result + "条记录受到影响--");
}
}
提示错误如下:
---------- 运行JAVA程序 ----------
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'graduation_project.student_table' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2728)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1811)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
at ExecuteDML.insertDate(ExecuteDML.java:26)
at ExecuteDML.main(ExecuteDML.java:33)
输出完成 (耗时 2 秒) - 正常终止
各位帮忙看看,感激不尽!
|