今天蒸腾半天弄不清这个问题,我做个表出来这个表名的地方出了问题String createtable="CREATE TABLE USER在这里,我用USER或user都提示我USER附近有语法错误,但是这个表名一换就什么事又都没了,USER不管大写小写都报这个错误,难道不让用这个名字建表???怎么这么奇怪?有人遇到过么import java.sql.*;
public class aaa{
public static void main(String[] args){
String url="jdbc:odbc:javaone";
String createtable="CREATE TABLE USER"+"(cofname varchar(32),"+"supit int,"+"price float,"+"sales int,"+"total int)";
Connection con;
Statement stmt;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e){
e.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"sa","");
stmt=con.createStatement();
stmt.executeUpdate(createtable);
stmt.close();
con.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
public class aaa{
public static void main(String[] args){
String url="jdbc:odbc:javaone";
String createtable="CREATE TABLE USER"+"(cofname varchar(32),"+"supit int,"+"price float,"+"sales int,"+"total int)";
Connection con;
Statement stmt;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e){
e.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"sa","");
stmt=con.createStatement();
stmt.executeUpdate(createtable);
stmt.close();
con.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
这是我在MYSQL5.0里做的实验。
mysql> create table user(name char(10));
Query OK, 0 rows affected (0.03 sec)
由此得出user不是关键字。之所以你使用USER做表明出错,这可能有一个原意是原来的数据库里已经存在了一个叫做user的表。你的程序每执行一次都要尝试创建一个叫做user的表,这可能造成冲突。
以上回复仅供参考。
由此得出user不是关键字。之所以你使用USER做表明出错,这可能有一个原意是原来的数据库里已经存在了一个叫做user的表。你的程序每执行一次都要尝试创建一个叫做user的表,这可能造成冲突。
-------------------------------------------------------------------------------------
由此得出user不是关键字。之所以你使用USER坐表名出错,这可能是原来的数据库里已经存在了一个叫做user的表。你的程序每执行一次都要尝试创建一个叫做user的表,这可能造成冲突。
PoemCode(诗意代码之魔数) 谢谢指正