[英]How to alter table in MySql and add column in Java?
I'm trying to add a column to my table but I'm getting an error saying my syntax is wrong. 我正在尝试向表中添加一列,但出现错误,提示我的语法错误。 I'm stuck, any ideas on correct syntax at line 2 on here?
我被卡住了,对这里第2行的正确语法有任何想法吗?
String myColumnType = "DECIMAL";
st.executeUpdate("ALTER TABLE stocks.stockvalue ADD " + myColumnName + " " + myColumnType);
String updateTableSQL = ("UPDATE stocks.stockvalue SET stockvalue." + myColumnName + " = ? WHERE stockvalue.stockvalue_id = " + count);
PreparedStatement preparedStatement = conn.prepareStatement(updateTableSQL);
preparedStatement.setDouble(2, stockV);
preparedStatement.executeUpdate();
System.out.println("Done");
preparedStatement.close();
conn.close();
The syntax for adding column to existing table is 将列添加到现有表的语法是
ALTER TABLE table_name
ADD column_name column-definition;
For example , 例如 ,
"ALTER TABLE stockvalue ADD " + myColumnName + " " + myColumnType “ ALTER TABLE股票价值添加” + myColumnName +“” + myColumnType
I think you missed word TABLE in statement. 我认为您在声明中遗漏了TABLE字。 Try it.
试试吧。 Hope this help you..
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.