Java Web App-尽管连接正常,但无法编辑数据库

Java Web App-尽管连接正常,但无法编辑数据库,java,mysql,database,jakarta-ee,web,Java,Mysql,Database,Jakarta Ee,Web,我正在使用maven创建java web应用程序。 我添加了mySQL本地数据库作为数据源,当我测试连接时一切正常,但是当我启动应用程序并尝试添加新记录时,它不工作,我的意思是代码正在执行,应用程序正在工作,但数据库中没有新数据。我也无法检查数据库中是否有一些数据。并没有错误或其他任何东西,但其他指令并没有连接到数据库正常工作。 在我的web.xml中 <resource-ref> <res-ref-name>jdbc/DSTestPool</res-ref

我正在使用maven创建java web应用程序。 我添加了mySQL本地数据库作为数据源,当我测试连接时一切正常,但是当我启动应用程序并尝试添加新记录时,它不工作,我的意思是代码正在执行,应用程序正在工作,但数据库中没有新数据。我也无法检查数据库中是否有一些数据。并没有错误或其他任何东西,但其他指令并没有连接到数据库正常工作。 在我的web.xml中

<resource-ref>
    <res-ref-name>jdbc/DSTestPool</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref> 
我的datasources.xml如下所示

public class UsersDAO {
    private DataSource ds;
    public UsersDAO(DataSource ds) {
        this.ds = ds;
    }
    public void createUser(User user){
        Connection con = null;
        PreparedStatement pst = null;
        try {
            con = ds.getConnection("root","");
            String sql="insert into users (Username,Password,Valid) values(?,?,?)";
            pst = con.prepareStatement(sql);
            pst.setString(1, user.getLogin());
            pst.setString(2, user.getPassMD5());
            pst.setInt(3,1);
            pst.executeUpdate();
        } catch (Exception e) {
            System.out.println(e);
        } finally {
            DbTools.closeQuietly(pst, con);
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="DataSourceManagerImpl" format="xml" hash="4078573267">
    <data-source source="LOCAL" name="MySQL - psi3@localhost" uuid="c2a621c7-089c-4d40-9767-1387f9bfb343">
      <driver-ref>mysql</driver-ref>
      <synchronize>true</synchronize>
      <jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
      <jdbc-url>jdbc:mysql://localhost:3306/psi3</jdbc-url>
      <driver-properties>
        <property name="zeroDateTimeBehavior" value="convertToNull" />
        <property name="tinyInt1isBit" value="false" />
        <property name="characterEncoding" value="utf8" />
        <property name="characterSetResults" value="utf8" />
        <property name="yearIsDateType" value="false" />
      </driver-properties>
      <libraries />
    </data-source>
  </component>
</project>

mysql
符合事实的
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/psi3
pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>psi_java</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>psi_java</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jettyVersion>9.2.5.v20141112</jettyVersion>
    </properties>



    <dependencies>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>${jettyVersion}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
<!-- This plugin is needed for the servlet example -->
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jettyVersion}</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <jettyXml>
                            ${basedir}/src/main/webapp/WEB-INF/jetty.xml
                    </jettyXml>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.34</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.commons</groupId>
                        <artifactId>commons-dbcp2</artifactId>
                        <version>2.0.1</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>javax.servlet-api</artifactId>
                        <version>3.0.1</version>
                    </dependency>
                </dependencies>
            </plugin> 
        </plugins>
    </build>

</project>

4.0.0
com.mycompany
爪哇岛
1.0-快照
罐子
爪哇岛
UTF-8
9.2.5.v20141112
org.eclipse.jetty
jetty服务器
${jettyVersion}
朱尼特
朱尼特
4.8.2
测验
org.eclipse.jetty
jetty maven插件
${jettyVersion}
2.
${basedir}/src/main/webapp/WEB-INF/jetty.xml
mysql
mysql连接器java
5.1.34
org.apache.commons
commons-dbcp2
2.0.1
javax.servlet
javax.servlet-api
3.0.1
我尝试了一些方法,但似乎没有任何效果,测试表明连接正常,我不知道该怎么办。我用java编写了一些应用程序,但这是我第一次使用java web,我不知道该怎么做,所以如果有人能帮助我,我将不胜感激。
我正在使用IntelliJ IDEA 14.0.3。

尝试直接从mysql客户端添加记录,看看会发生什么,为什么在jetty.xml中声明JNDI名称,在datasources.xml中声明一些类似的信息?关于我的信息,哪个框架读取datasource.xml?是ext.js吗?@aurelius我已经试着从我的客户那里添加记录了,而且效果很好。@vincent说实话,我不知道,我的教授把它作为一个模板,我正在研究它,我不知道它到底是如何工作的,我正在努力理解它,但正如我说的,这是我第一次使用java web,所以我仍然不了解很多东西。你在你的项目中使用了哪些框架?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>psi_java</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>psi_java</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jettyVersion>9.2.5.v20141112</jettyVersion>
    </properties>



    <dependencies>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>${jettyVersion}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
<!-- This plugin is needed for the servlet example -->
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jettyVersion}</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <jettyXml>
                            ${basedir}/src/main/webapp/WEB-INF/jetty.xml
                    </jettyXml>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.34</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.commons</groupId>
                        <artifactId>commons-dbcp2</artifactId>
                        <version>2.0.1</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>javax.servlet-api</artifactId>
                        <version>3.0.1</version>
                    </dependency>
                </dependencies>
            </plugin> 
        </plugins>
    </build>

</project>