简体   繁体   English

MySQL + JAVA-无法将表格插入另一个

[英]MySQL + JAVA - Can't insert a table into another

I can't seem to insert my old table into the new table. 我似乎无法将旧表插入新表。 Very weird 很奇怪

Code: 码:

INSERT INTO 'newhawk_playewadwds' (`player_id`,'player') SELECT `player_id`,'player' FROM 'hawk_playewadwds';

Error: 错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You
have an error in your SQL syntax; check the manual that corresponds to your MySQ
L server version for the right syntax to use near ''newhawk_playewadwds' (`playe
r_id`,'player') SELECT `player_id`,'player' FROM 'h' at line 1

Extra info: 额外信息:

Both tables exist and have slightly diffrent column structors (One has a varchar(50), while the other doesn't). 这两个表都存在并且具有略有不同的列结构(一个具有varchar(50),而另一个则没有)。 Which is why i included the direct columns in the statement. 这就是为什么我在语句中包括直接列的原因。

Quotes are delimiters for strings. 引号是字符串的定界符。 Use backticks to escape column and table names, not quotes. 使用反引号转义列和表名,而不是引号。

INSERT INTO `newhawk_playewadwds` (`player_id`,`player`) 
SELECT `player_id`,`player` 
FROM `hawk_playewadwds`;

But you actually only need to escape the reserved words . 但是实际上您只需要转义保留字即可

Try to replace ' char with table names and for column player as below 尝试用表名和列player替换' char,如下所示

INSERT INTO `newhawk_playewadwds` (`player_id`,`player`) 
SELECT `player_id`,`player` 
FROM `hawk_playewadwds`;

Use backticks across the query. 在查询中使用反引号。 You are using backticks and single quotes. 您正在使用反引号和单引号。 Either use backticks or remove the single quotes: 使用反引号或删除单引号:

-- This will work (Backticks only)
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`) 
SELECT `player_id`,`player` 
FROM `hawk_playewadwds`;

-- This will also work (No backticks and no single quotes)
INSERT INTO newhawk_playewadwds (player_id,player) 
SELECT player_id,player 
FROM hawk_playewadwds;

Another thing, as you mentioned column structures are different, 另一件事,正如您提到的列结构不同,

  1. If newhawk_playewadwds has column > 50, and hawk_playewadwds has < 50, It shouldn't be a problem 如果newhawk_playewadwds列> 50,而hawk_playewadwds列<50,则应该没问题
  2. If hawk_playewadwds' has > 50 and newhawk_playewadwds` has <50, then do either of the following: 如果hawk_playewadwds' has > 50 and <50,则执行以下任一操作:

    1. Increase the size of the new table newhawk_playewadwds to same size of hawk_playewadwds 将新表newhawk_playewadwds大小hawk_playewadwds大小
    2. Use Substring in select as: 在选择中使用Substring作为:

       INSERT INTO `newhawk_playewadwds` (`player_id`,`player`) SELECT `player_id`,SUBSTRING(`player` ,1,50) FROM `hawk_playewadwds`; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用Java将byte []插入MySQL - Can't insert byte[] into MySQL using java 尝试将数据插入Mysql表不起作用(Java) - Trying to insert data into Mysql Table doesn't work (Java) 我们如何直接在Java中的mysql表中插入xml文件? - How can we insert an xml file directly into a mysql table in java? 使用java将数据插入mySQL表 - Insert data into mySQL table with java 我的Eclipse中的Java代码似乎可以运行,但是MySQL为什么不将其插入表中? 我们可以使用两个try catch吗? - My java Code in Eclipse seems to run but MySQL doesn't insert it into the table why? Can we use two try catch? java,mysql-为什么不工作,从一个表中获取最后一个插入的ID,然后将其再次插入另一个表中? - java,mysql - why not working get last inserted id from one table and insert it again on another table? Java/Mysql 从一个表中选择主键值并将它们作为外键插入到另一个表中 - Java/Mysql Selecting Primary Key values from one table and Insert them to another table as Foreign Keys 无法在Java的高分表中插入行 - Can't insert a line in my highscore table in Java mysql,java - 从一个表中获取最后插入的自动增量 id 并将其再次插入到另一个表中 - mysql, java - Get last inserted auto increment id from one table and insert it again on another table 无法将数据插入MySQL - can't insert data into mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM