我正在使用jdbc
创建一些数据库表。在其中一个表中,我收到此错误消息:TYPE 'MEET' does not exist.
。有什么想法吗?
代码如下:
public class MeetingDAO {
public static String getTableString(){
String meetingTable = "create table project ( " +
"meeting_id integer not null, " +
"timestamp meet, " +
"project_key varchar(10), " +
"primary key(meeting_id))";
return projectTable;
}
}
public class JDBCUtil {
private static final String dbURL= "jdbc:derby:MyDB;create=true;";
private static final String userID = "moon";
private static final String password = "moonmoon";
public static void init(){
makeTable(MeetingDAO.getTableString());
}
private static void makeTable(String tableSQL){
Connection conn = null;
try {
conn = JDBCUtil.getConnection();
Statement stmt = null;
try {
stmt = conn.createStatement();
stmt.executeUpdate(tableSQL);
}
finally {
JDBCUtil.closeStatement(stmt);
}
JDBCUtil.commit(conn);
}
catch (SQLException e) {
System.out.println(e.getMessage());
JDBCUtil.rollback(conn);
}
finally {
JDBCUtil.closeConnection(conn);
}
}
public static Connection getConnection() throws SQLException{
Driver derbyEmbededDriver = new EmbeddedDriver();
DriverManager.registerDriver(derbyEmbededDriver);
Connection conn = DriverManager.getConnection(dbURL, userID, password);
conn.setAutoCommit(false);
return conn;
}
public static void closeConnection(Connection conn){
try{
if(conn != null)
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
public static void closeStatement(Statement stmt){
try {
if(stmt != null)
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void closeResultSet(ResultSet rs){
try {
if(rs != null)
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void commit(Connection conn){
try {
if(conn != null)
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void rollback (Connection conn){
try {
if(conn != null)
conn.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:3)
只需交换这两个词:
timestamp meet
到
meet timestamp
首先是列命名,然后是列数据表。
答案 1 :(得分:2)
您混合了列meet
的列名和数据类型。
public class MeetingDAO {
public static String getTableString(){
String meetingTable = "create table project ( " +
"meeting_id integer not null, " +
"meet timestamp, " +
"project_key varchar(10), " +
"primary key(meeting_id))";
return projectTable;
}
}