Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 无法执行JDBC批处理更新错误_Hibernate_Jsp_Servlets - Fatal编程技术网

Hibernate 无法执行JDBC批处理更新错误

Hibernate 无法执行JDBC批处理更新错误,hibernate,jsp,servlets,Hibernate,Jsp,Servlets,我得到“Hibernate:插入用户(用户名、密码、电子邮件、电话、城市、ID)值(?,,,,,,,,?) 无法执行JDBC批处理更新 错误“ 这个错误。请帮助我 我写过这样的代码 Jsp <body> <h1>Registration Form</h1> <form action="./UserControllerServlet" method="post"> <table cellpadding="3pt">

我得到“Hibernate:插入用户(用户名、密码、电子邮件、电话、城市、ID)值(?,,,,,,,,?) 无法执行JDBC批处理更新 错误“ 这个错误。请帮助我

我写过这样的代码

Jsp

<body>
<h1>Registration Form</h1>
<form action="./UserControllerServlet" method="post">
    <table cellpadding="3pt">
        <tr>
            <td>User Name :</td>
            <td><input type="text" name="userName" size="30" /></td>
        </tr>
        <tr>
            <td>Password :</td>
            <td><input type="password" name="password1" size="30" /></td>
        </tr>

        <tr>
            <td>Confirm Password :</td>
            <td><input type="password" name="password2" size="30" /></td>
        </tr>
        <tr>
            <td>email :</td>
            <td><input type="text" name="email" size="30" /></td>
        </tr>
        <tr>
            <td>Phone :</td>
            <td><input type="text" name="phone" size="30" /></td>
        </tr>
        <tr>
            <td>City :</td>
            <td><input type="text" name="city" size="30" /></td>
        </tr>
    </table>
    <p />
    <input type="submit" value="Register" />
</form>
User.java

public class User {

private int id;
private String userName;
private String password1;
private String email;
private String phone;
private String city;
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}
public String getPassword1() {
    return password1;
}
public void setPassword1(String password1) {
    this.password1 = password1;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}
public String getPhone() {
    return phone;
}
public void setPhone(String phone) {
    this.phone = phone;
}
public String getCity() {
    return city;
}
public void setCity(String city) {
    this.city = city;
}
用户道

public class UserDAO {

public void addUserDetails(String userName,String password,String email,String phone,String city){

    try{
        Configuration config=new Configuration();

        SessionFactory sessionFactory=config.configure().buildSessionFactory();

        Session session=sessionFactory.openSession();

        Transaction transaction=session.beginTransaction();

        User user=new User();

        user.setUserName(userName);
        user.setPassword1(password);
        user.setEmail(email);
        user.setPhone(phone);
        user.setCity(city);

        session.save(user);
        transaction.commit();

        System.out.println("\n\n Detais Added \n\n");


    }
    catch(HibernateException e){
        System.out.println(e.getMessage());
        System.out.println("error");
    }
hibernate.cfg.xml

<hibernate-configuration>

<session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@chetan:1521:XE</property>
    <property name="connection.username">system</property> 
    <property name="connection.password">manager</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>             

    <mapping resource="com/jwt/hibernate/bean/user.hbm.xml" /> 
</session-factory>

oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@chetan:1521:XE
系统
经理
1.
org.hibernate.dialen.oracle10galent
org.hibernate.cache.NoCacheProvider
真的
创造

user.hbm.xml

<hibernate-mapping>
<class name="com.jwt.hibernate.bean.User" table="USER">
    <id column="ID" name="id" type="java.lang.Integer" />
    <property column="USER_NAME" name="userName" type="java.lang.String" />
    <property column="PASSWORD" name="password1" type="string" />
    <property column="EMAIL" name="email" type="java.lang.String" />
    <property column="PHONE" name="phone" type="java.lang.String" />
    <property column="CITY" name="city" type="java.lang.String" />
</class>


这可能是因为USER是关键字,您需要将它们放在backtick中,如

insert into `USER` (USER_NAME, PASSWORD, EMAIL, PHONE, CITY, ID) values (?, ?, ?, ?, ?, ?)
您可以通过以下方式强制Hibernate在生成的SQL中引用标识符: 将表名或列名包含在映射中的反标记中 文件。Hibernate将为SQL使用正确的引号样式 方言。这通常是双引号,但SQL Server使用 括号和MySQL使用反勾号


请添加您的代码和完整的堆栈跟踪。欢迎使用堆栈溢出!请阅读并尝试编辑您的问题。有了高质量的问题,你会更快地得到更好的答案。谢谢hibernate SQL输出和绑定日志非常感谢您的建议。我只是将User类更改为UserInfo类,它就可以工作了。谢谢
insert into `USER` (USER_NAME, PASSWORD, EMAIL, PHONE, CITY, ID) values (?, ?, ?, ?, ?, ?)