Java 如何有效地使用事先准备好的报表?

Java 如何有效地使用事先准备好的报表?,java,jakarta-ee,jdbc,Java,Jakarta Ee,Jdbc,这是我的代码,运行良好,没有任何错误…但在我的数据库中,它是nt 更新我无法理解的值的原因有任何机构可以帮助我吗 这就是为什么它的nt更新id为102的age值…尝试使用 import java.sql.*; public class Login { public static void main(String args[]) throws SQLException { Connection con = null; PreparedStatemen

这是我的代码,运行良好,没有任何错误…但在我的数据库中,它是nt 更新我无法理解的值的原因有任何机构可以帮助我吗 这就是为什么它的nt更新id为102的age值…

尝试使用

import java.sql.*;
public class Login
{
    public static void main(String args[]) throws SQLException
    {
        Connection con = null;
        PreparedStatement stmt = null;
        Statement st = null;
        try {
            Driver driver = new oracle.jdbc.driver.OracleDriver();
            DriverManager.registerDriver(driver);
            System.out.println("coneecting to the database:");
            con = DriverManager.getConnection("driverURL","usrr","pass");
            System.out.println("creating statement");
            String sql = "Update abhi SET age = ? WHERE id = ?";
            stmt = con.prepareStatement(sql);
            stmt.setInt(1, 35);
            stmt.setInt(2,102);
            int rows = stmt.executeUpdate();
            S.O.P("rows updated"+rows);
            stmt.close();
            String sql2;
            sql2 = "select * from abhi";
            st = con.createStatement();
            ResultSet rs = st.executeQuery(sql2);
            while(rs.next())
            {
                System.out.println("hi");
                int age = rs.getInt("age");
                System.out.println("age is"+age);
            }
            rs.close();
            stmt.close();
            con.close();
        }
        catch(SQLException e) {
            e.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            try {
                if (st != null)
                    st.close();
            }
            catch(Exception e) {
                 // nthing to do
            }
            try {
                if(con != null)
                    con.close();
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        System.out.println("good bye johny");
    }
}
在甲骨文中

默认的数据库事务模式是两阶段提交

i、 e.插入或更新数据后

您应该显式地提交操作,以便在oracle数据库中持久化数据

但是在这里,我没有看到您的代码中有任何提交

您可以在代码中检查这个问题吗

你应该使用-

con.setAutoCommit(假)在代码开头


正如其他人提到的,尝试像这样使用连接提交

con.commit(); to commit the data

我看不到一个承诺。(请尝试并格式化您的代码,您发布代码时很难理解。)连接到数据库:创建声明再见johny我只收到此o/p,即使我使用了1以上………连接更新后提交查询我仍然无法理解我代码中的问题。。。我已经在STMT.EXECUTEuPDATE()之后包含了CON.COMMIT();如果更新的行数为0,则表示表中没有ID=102的行。检查您的数据。检查您是否连接到正确的数据库。检查您在数据库浏览器中查看的数据是否为提交的数据。我检查了几次EVN我创建了一个新表并插入102作为ID,但无法理解任何内容。EVN它的NT在控制台上打印任何值。请任何人查看我的代码并告诉我错误的确切位置。谢谢大家,但我得到了,我已经做了一些书面询问中的错误
con.commit(); to commit the data
import java.sql.*;
public class Login
{
public static void main(String args[]) throws SQLException
{
    Connection con = null;
    PreparedStatement stmt = null;
    Statement st = null;
    try
    {
        Driver driver = new oracle.jdbc.driver.OracleDriver();
        DriverManager.registerDriver(driver);
        System.out.println("coneecting to the database:");

    con = DriverManager.getConnection("driverURL","usrr","pass");       
    con.setAutoCommit(false);
    System.out.println("creating statement");

    String sql = "Update abhi SET age = ? WHERE id = ?";

    stmt = con.prepareStatement(sql);

    stmt.setInt(1, 35);

    stmt.setInt(2,102);

    int rows =    stmt.executeUpdate();

    S.O.P("rows updated"+rows);

    stmt.close();
    con.commit();
    String sql2;

    sql2 = "select * from abhi";

    st = con.createStatement();

    ResultSet rs = st.executeQuery(sql2);

    while(rs.next())
    {
        System.out.println("hi");


        int age = rs.getInt("age");

        System.out.println("age is"+age);
    }

                 rs.close();

    stmt.close();

    con.close();
}

catch(SQLException e)
{
    e.printStackTrace();
}
catch (Exception e)
         {
    e.printStackTrace();    
}
finally
{
    try
    {
        if(st!=null)
            st.close();
    }

    catch(Exception e) 
    {
               // nthing to do

                 }
    try
    {
        if(con!=null)

        con.close();
    }
    catch (Exception e)
    {

                e.printStackTrace();

                 }


         }

       System.out.println("good bye johny");

        }