1

所以这是我的代码

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/test"; 
//ResultSet rs = null;
PreparedStatement psmnt = null;
//FileInputStream fis;

connection = DriverManager.getConnection(connectionURL,"root","123");
psmnt = connection.prepareStatement("insert into Table1 (name, desc, r,g,b," +
    "varR,varG,varB,skewnessR,skewnessG,skewnessB)values(?,?,?,?,?,?,?,?,?,?,?)");
final String text2 = setName.getText();
final String text3=setDesc.getText();
psmnt.setString(1,text2);
psmnt.setString(2,text3);
psmnt.setString(3,stringMeanR);
psmnt.setString(4,stringMeanG);
psmnt.setString(5,stringMeanB);
psmnt.setString(6,stringVarianceR);
psmnt.setString(7,stringVarianceG);
psmnt.setString(8,stringVarianceB);
psmnt.setString(9,stringSkewnessR);
psmnt.setString(10,stringSkewnessG);
psmnt.setString(11,stringSkewnessB);

//fis = new FileInputStream(f);

//psmnt.setBinaryStream(2, (InputStream)fis, (int)(f.length()));
int s = psmnt.executeUpdate();
psmnt.close();
connection.close();
if(s>0) {
    System.out.println("Uploaded successfully !");
}
else {
    System.out.println("Unsucessfull to upload image.");
}                      

问题是我收到以下错误

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, r,g,b,varR,varG,varB,skewnessR,skewnessG,skewnessB)values('','','105.59 , ' at line 1
4

2 回答 2

4

desc是保留的 SQL 关键字(用于order by foo desc)。更改您命名为“desc”的列的名称(或使用反引号对其进行转义,但我会更改名称以使其更容易)

于 2013-06-01T14:37:13.570 回答
1

desc是 SQL 中用于描述 SQL 表的保留关键字。因此,如果您的列名是“描述”,那么它应该是“描述”;desc不是MySQL 中保留的用于描述表本身或显示用于创建表的 SQL 代码的“desc” 。

于 2013-06-01T14:39:28.663 回答