【问题标题】:Value not found or ?? when insert into mysql未找到值或 ??插入mysql时
【发布时间】:2020-04-13 06:26:22
【问题描述】:

大家好,当我想将数据插入我的数据库时遇到问题...

insert into New_Single_Order_Response (AveragePrice, BodyLength, CheckSum, ClOrdID, CumQty, Currency, ExecID, ExecTransType, ExecType, Fix_Protocol, LastShares, LeavesQty, MsgSeqNum, MsgType, OrdStatus, OrdType, OrderID, OrderQty, SenderCompId, SendingTime, Side, Symbol, TargetCompID, TransactTime) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

但我的数据无法插入到我的数据库中……为什么会这样?

首先我使用

设置了我的 persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
             <persistence-unit name="FastMatch" transaction-type="RESOURCE_LOCAL">
              <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
              <class>com.dxtr.hibernate.newOrderSingleEntity</class>
              <properties>
             <property name="eclipselink.logging.level" value="INFO"/>
             <property name="eclipselink.logging.level.sql" value="FINE"/>
            <property name="eclipselink.logging.parameters" value="true"/> 
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://Url/dxtr_trades" />
            <property name="javax.persistence.jdbc.user" value="username" />
            <property name="javax.persistence.jdbc.password" value="password" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL57InnoDBDialect" />
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="eclipselink.logging.level.connection" value="FINEST"/>
              </properties>
             </persistence-unit>
</persistence>    

这是我的实体

 @Entity
    @Table(name="New_Single_Order_Response")
    public class newOrderSingleEntity  implements Serializable{
         private static final long serialVersionUID = -1234424538928L;
          @Id
            @Column(name="response_id")
            @GeneratedValue(strategy=GenerationType.IDENTITY)
            private Integer id;

            @Column(name="Fix_Protocol")
            private String FixProtocol;

            @Column(name="BodyLength")
            private Integer BodyLength;

            @Column(name="MsgSeqNum")
            private Integer MsgSeqNum;

            @Column(name="MsgType")
            private String MsgType;

            @Column(name="SenderCompId")
            private String SenderCompId;

            @Column(name="SendingTime")
            private String SendingTime;

            @Column(name="TargetCompID")
            private String TargetCompID;

            @Column(name="AveragePrice")
            private Double AveragePrice;

            @Column(name="ClOrdID")
            private String ClOrdID;

            @Column(name="CumQty")
            private double CumQty;

            @Column(name="Currency")
            private String Currency;

            @Column(name="ExecID")
            private String ExecID;

            @Column(name="LastShares")
            private double LastShares;

            @Column(name="OrderQty")
            private Double OrderQty;

            @Column(name="OrdStatus")
            private String OrdStatus;

            @Column(name="OrdType")
            private String OrdType;

            @Column(name="Side")
            private Integer Side;

            @Column(name="Symbol")
            private String Symbol;

            @Column(name="TransactTime")
            private String TransactTime;

            @Column(name="ExecType")
            private String ExecType;

            @Column(name="LeavesQty")
            private double LeavesQty;

            @Column(name="CheckSum")
            private Integer CheckSum;

            @Column(name="ExecTransType")
            private String ExecTransType;

            @Column(name="OrderID")
            private String OrderID;


            public Integer getResponse_ID() {
                return this.id;
            }

            public void setResponse_ID(Integer id) {
                this.id = id;
            }

            public String getFixProtocol() {
                return this.FixProtocol;
            }

            public void setFixProtocol(String FixProtocol) {
                this.FixProtocol = FixProtocol;
            }

            public Integer getBodyLength() {
                return this.BodyLength;
            }

            public void setBodyLength(Integer BodyLength) {
                this.BodyLength = BodyLength;
            }

            public Integer getMsgSeqNum() {
                return this.MsgSeqNum;
            }

            public void setMsgSeqNum(Integer MsgSeqNum) {
                this.MsgSeqNum = MsgSeqNum;
            }


            public String getMsgType() {
                return this.MsgType;
            }

            public void setMsgType(String MsgType) {
                this.MsgType = MsgType;
            }

            public String getSenderCompId() {
                return this.SenderCompId;
            }

            public void setSenderCompId(String SenderCompId) {
                this.SenderCompId = SenderCompId;
            }

            public String getSendingTime() {
                return this.SendingTime;
            }

            public void setBodyLength(String SendingTime) {
                this.SendingTime = SendingTime;
            }

            public String getTargetCompID() {
                return this.TargetCompID;
            }

            public void setTargetCompID(String TargetCompID) {
                this.TargetCompID = TargetCompID;
            }

            public Double getAveragePrice() {
                return this.AveragePrice;
            }

            public void setAveragePrice(Double AveragePrice) {
                this.AveragePrice = AveragePrice;
            }

            public String getClOrdID() {
                return this.ClOrdID;
            }

            public void setClOrdID(String ClOrdID) {
                this.ClOrdID = ClOrdID;
            }

            public double getCumQty() {
                return this.CumQty;
            }

            public void setCumQty(double CumQty) {
                this.CumQty = CumQty;
            }

            public String getCurrency() {
                return this.Currency;
            }

            public void setCurrency(String Currency) {
                this.Currency = Currency;
            }

            public String getExecID() {
                return this.ExecID;
            }

            public void setExecID(String ExecID) {
                this.ExecID = ExecID;
            }

            public double getLastShares() {
                return this.LastShares;
            }

            public void setLastShares(double LastShares) {
                this.LastShares = LastShares;
            }

            public Double getOrderQty() {
                return this.OrderQty;
            }

            public void setOrderQty(Double OrderQty) {
                this.OrderQty = OrderQty;
            }

            public String getExecType() {
                return this.ExecType;
            }

            public void setExecType(String ExecType) {
                this.ExecType = ExecType;
            }

            public String getOrdStatus() {
                return this.OrdStatus;
            }

            public void setOrdStatus(String OrdStatus) {
                this.OrdStatus = OrdStatus;
            }

            public String getOrdType() {
                return this.OrdType;
            }

            public void setOrdType(String OrdType) {
                this.OrdType = OrdType;
            }

            public Integer getSide() {
                return this.Side;
            }

            public void setSide(Integer Side) {
                this.Side = Side;
            }

            public String getSymbol() {
                return this.Symbol;
            }

            public void setSymbol(String Symbol) {
                this.Symbol = Symbol;
            }

            public String getTransactTime() {
                return this.TransactTime;
            }

            public void setTransactTime(String TransactTime) {
                this.TransactTime = TransactTime;
            }

            public double getLeavesQty() {
                return this.LeavesQty;
            }

            public void setLeavesQty(double LeavesQty) {
                this.LeavesQty = LeavesQty;
            }

            public Integer getCheckSum() {
                return this.CheckSum;
            }

            public void setCheckSum(Integer CheckSum) {
                this.CheckSum = CheckSum;
            }

            public String getExecTransType() {
                return this.ExecTransType;
            }

            public void setExecTransType(String ExecTransType) {
                this.ExecTransType = ExecTransType;
            }

            public String getOrderID() {
                return this.OrderID;
            }

            public void setOrderID(String OrderID) {
                this.OrderID = OrderID;
            }

            public String toString() {
                return "OrderDetail?= Id: " + this.id + ", ClOrdID: " + this.ClOrdID + ", ExecID No.: " + this.ExecID + ", Symbol: " + this.Symbol;
            }



    }

这是我插入数据库的代码

newOrderSingleEntity newordersingleObj = new newOrderSingleEntity();
                    newordersingleObj.setSymbol(message.getString(Symbol.FIELD));
                    System.out.print(" symbol "+message.getString(Symbol.FIELD));
                    newordersingleObj.setMsgType(tipeMessage);
                    System.out.print(" tipeMessage "+tipeMessage);
                    newordersingleObj.setBodyLength(216);
                    System.out.print(" Body Length "+216);
                    newordersingleObj.setFixProtocol("FIX.4.2");
                    System.out.print("FixProtocol +FIX.4.2");
                    newordersingleObj.setTransactTime(message.getString(TransactTime.FIELD));
                    System.out.print(" time " +message.getString(TransactTime.FIELD));
                    newordersingleObj.setClOrdID(message.getString(ClOrdID.FIELD));
                    System.out.print(" ClOrdID "+message.getString(ClOrdID.FIELD));
                    newordersingleObj.setOrderID(message.getString(OrderID.FIELD));
                    System.out.print(" OrderID "+message.getString(OrderID.FIELD));
                    newordersingleObj.setExecID(message.getString(ExecID.FIELD));
                    System.out.print(" ExecID "+message.getString(ExecID.FIELD));
                    newordersingleObj.setExecTransType(message.getString(ExecTransType.FIELD));
                    System.out.print(" ExecTransType "+message.getString(ExecTransType.FIELD));
                    newordersingleObj.setOrdType(message.getString(OrdType.FIELD));
                    System.out.print(" OrdType "+message.getString(OrdType.FIELD));
                    newordersingleObj.setExecType(message.getString(ExecType.FIELD));
                    System.out.print(" ExecType "+message.getString(ExecType.FIELD));
                    newordersingleObj.setOrdStatus(message.getString(OrdStatus.FIELD));
                    System.out.print(" OrdStatus "+message.getString(OrdStatus.FIELD));
                    newordersingleObj.setSide(message.getInt(Side.FIELD));
                    System.out.print(" Side "+message.getInt(Side.FIELD));
                    newordersingleObj.setOrderQty(message.getDouble(OrderQty.FIELD));
                    System.out.print(" OrderQty "+message.getDouble(OrderQty.FIELD));
                    newordersingleObj.setLeavesQty(message.getDouble(LeavesQty.FIELD));
                    System.out.print(" LeavesQty "+message.getDouble(LeavesQty.FIELD));
                    newordersingleObj.setCumQty(message.getDouble(CumQty.FIELD));
                    System.out.print(" CumQty "+message.getDouble(CumQty.FIELD));
                    newordersingleObj.setLastShares(message.getInt(LastShares.FIELD));
                    System.out.print(" LastQty "+message.getInt(LastShares.FIELD));
    } catch (FieldNotFound e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

我用过这样的 try catch 但没有错误...我认为我的应用程序也无法运行我的休眠模式

当我记录我想要插入的值时,存在并且该值不存在????那么我的问题到底是什么?以及如何解决我的问题?我想要做的是将该数据插入到 mydatabase mysql5.7

这是我在这里使用的库

在我更改了我的 mysqlconnector 后,我得到了类似的信息

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Mon Apr 13 08:28:46 UTC 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL $.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 exist$ng applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting us$SSL=false, or set useSSL=true and provide truststore for server certificate verification.

究竟是什么问题?

【问题讨论】:

  • 您已经发布了除错误消息之外的所有内容。你在catch 块中写过e.printStackTrace() 吗?如果没有,请这样做并再次执行您的程序。这样做之后,您可能不需要任何人的帮助。
  • 是的,我有 catch } catch (FieldNotFound e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace();但是错误没有向我显示它就像我的休眠无法连接到我的数据库......为什么这样?
  • 我建议你从一些基础教程开始,比如codejava.net/frameworks/hibernate/…
  • mysql5.7 有什么例子吗?有 mysql 5.5 的教程

标签: java mysql hibernate jpa mysql-5.7


【解决方案1】:

在我使用 mysql 连接器 8 更新我的 mysql-connector 之后,然后在我的 persistence.xml 中使用之后,这是关闭的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    相关资源
    最近更新 更多