Reputation: 1123
I'm making some database tables using jdbc
. On one of the tables I get this error message : TYPE 'MEET' does not exist.
. Any ideas why?
The code is below:
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();
}
}
}
Upvotes: 1
Views: 107
Reputation: 1272
You mixed up column name and data type for the column 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;
}
}
Upvotes: 2
Reputation: 12523
just swap these two words:
timestamp meet
to
meet timestamp
first there comes the column naming, after that the column datatyp.
Upvotes: 3