我正在尝试用java在Oracle DB中创建一个表。当我运行这个时,我收到错误
ORA-00900:无效的SQL语句
调用中的无效参数
我不知道如何解决这个问题,我所有的研究都是空洞的。
package Project2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Embedded {
private static String dbURL = "jdbc:oracle:thin:@query.engr.uconn.edu:1521:BIBCI";
private static Connection conn = null;
private static Statement stmt = null;
public static void main(String[] args) {
createConnection();
createTable();
//insertValue();
shutdown();
}
private static void createConnection() {
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
//Get a connection
conn = DriverManager.getConnection(dbURL, "cse4701", "datamine");
} catch (Exception except) {
except.printStackTrace();
}
}
private static void createTable() {
//String sql = "CREATE TABLE IG_READY (PatientId VARCHAR(20), APC integer, TP53 integer, KRAS integer, PIK3CA integer, PTEN integer, ATM integer, MUC4 integer, SMAD4 integer, SYNE1 integer, FBXW7 integer, Status integer)";
try {
stmt = conn.createStatement();
stmt.executeQuery("creat table CRCDB.IG_READY (PatientId VARCHAR(20), APC integer, TP53 integer, KRAS integer, PIK3CA integer, PTEN integer, ATM integer, MUC4 integer, SMAD4 integer, SYNE1 integer, FBXW7 integer, Status integer, PRIMARY KEY (PatientId));");
//stmt.executeQuery("use CRCDB");
stmt.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
private static void shutdown() {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
DriverManager.getConnection(dbURL + ";shutdown=true");
conn.close();
}
} catch (SQLException sqlExcept) {
System.out.println(sqlExcept.getMessage());
}
}
}
答案 0 :(得分:2)
错误在于你的sql语句
stmt.executeQuery("creat table CRCDB.IG_READY (PatientId VARCHAR(20), APC integer, TP53 integer, KRAS integer, PIK3CA integer, PTEN integer, ATM integer, MUC4 integer, SMAD4 integer, SYNE1 integer, FBXW7 integer, Status integer, PRIMARY KEY (PatientId));");
你误解了“创建表格”
首先执行带有小测试表的stmt,然后创建表
我希望这可以帮助你解决问题,如果我得到任何其他信息,我肯定会告诉你