weixin_45730374 2022-09-06 23:43 采纳率: 50%
浏览 24
已结题

关于#mysql#的问题,如何解决?

刚学JDBC,想修改mysql数据库的数据,但报错了,请各位指教
package com.itheima.数据库连接池;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

public class Test {
public static void main(String[] args) throws Exception, FileNotFoundException {
DriverManager.getConnection("jdbc:mysql:\\db1", "root", "1234");
Properties properties = new Properties();
properties.load(new FileReader("jdbc_1\druid.properties"));

    DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
    Connection connection = dataSource.getConnection();

    PreparedStatement preparedStatement = connection.prepareStatement("insert into emp(id,ename,joindate,salary,bouns) values (?,?,?,?,?)");
    preparedStatement.setInt(1, 23);
    preparedStatement.setString(2, "张三");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse("2019-3-4");
    preparedStatement.setDate(3, new java.sql.Date(date.getTime()));
    preparedStatement.setDouble(4, 7800);
    preparedStatement.setDouble(5, 1800);
    int i = preparedStatement.executeUpdate();
    System.out.println(i > 0 ? "修改成功" : "修改失败");
    preparedStatement.close();
    connection.close();
}

}

报错信息:
Connected to the target VM, address: '127.0.0.1:56905', transport: 'socket'
Tue Sep 06 23:39:31 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
九月 06, 2022 11:39:32 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'bouns' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.Util.getInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1912)
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2133)
at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2067)
at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5175)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2052)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeUpdate(DruidPooledPreparedStatement.java:256)
at com.itheima.数据库连接池.Test.main(Test.java:30)
Disconnected from the target VM, address: '127.0.0.1:56905', transport: 'socket'

  • 写回答

1条回答 默认 最新

  • 鑫仔的记忆 2022-09-07 09:04
    关注

    实体类中的字段名出错了,看一下sql语句中的bouns跟数据库里的是否一致,还有实体类中是否正确,检查数据库中的字段名与实体类中的字段名是否一致,特别要注意单词字母,比如数据库中没有该字段,实体类中出现了就会报这个错

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月15日
  • 已采纳回答 9月7日
  • 创建了问题 9月6日