[英]java.sql.SQLSyntaxErrorException: ORA-00928: missing SELECT keyword
I get this error when i was inserting some rows to database. 当我向数据库中插入一些行时出现此错误。
Code 码
public class InsertRowData {
public static void main(String[] args)throws ClassNotFoundException, SQLException{
Connection con = (Connection) DriverManager
.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL" , "system" , "system");
Statement statement = con.createStatement();
String dmlinsert = "insert into student(111,manoj,rawatrulz09)";
int rowseffected = statement.executeUpdate(dmlinsert);
System.out.println("no of rows effected" + rowseffected);
}
}
After searching in google I found the solution to remove single quotes from the column but still getting the same error. 在谷歌搜索后,我找到了从列中删除单引号的解决方案,但仍然遇到相同的错误。 ps-I am a newbie ps-我是新手
This is a bad approach to insert any data into the Table. 将任何数据插入表中都是一种不好的方法。
String dmlinsert="insert into student(111,manoj,rawatrulz09)"
first of all, your query missing a syntax Values
. 首先,您的查询缺少语法Values
。
when columns are not mentioned while inserting, values
must contain same amount of data and respectively. 如果在插入时未提及列,则values
必须分别包含和相同的数据量。
But when inserting a data the best practice is to mention columns, so that if in later time you make any change to the table in database, your insert query stays stable. 但是,在插入数据时,最佳实践是提及列,以便以后在数据库中对表进行任何更改时,插入查询都保持稳定。 for eg: insert into student(id, name, email) values(111,'manoj','rawatrulz09')
. 例如: insert into student(id, name, email) values(111,'manoj','rawatrulz09')
。
Now, if in future you will add a column to this table, your insert query will still work as it has mentioned columns, but if you won't mention any columns then your code will start giving error when executed no of values don't match given to the table
etc... Good luck! 现在,如果将来要在此表中添加一列,则插入查询仍将按其提到的列继续工作,但是如果您不提及任何列,则执行代码时如果no of values don't match given to the table
则代码将开始出错no of values don't match given to the table
等...祝你好运! anyway, answer for your insert query: 无论如何,回答您的插入查询:
insert into student values(111,'manoj','rawatrulz09')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.