简体   繁体   English

结果集在mysql中给出空值

[英]Resultset giving a null value in mysql

this is part of my code 这是我的代码的一部分

String qn = request.getParameter("t0");
        String o1 = request.getParameter("t1");
        String o2 = request.getParameter("t2");
        String  o3 = request.getParameter("t3");
        String  o4 = request.getParameter("t4");
        String  an = request.getParameter("a");
        String d_id=null;
        String u=request.getParameter("u");
        String s=request.getParameter("s");
        String s1=request.getParameter("s1");
        String d=request.getParameter("d");
        //InputStream inputStream = null; // input stream of the upload file

        // obtains the upload file part in this multipart request


        Connection conn = null; // connection to the database
        String message = null;  // message will be sent back to client
        try {
             DriverManager.registerDriver(new com.mysql.jdbc.Driver());
             conn = DriverManager.getConnection(dbURL, dbUser, dbPass);
        Statement st=conn.createStatement();
        ResultSet rsta=st.executeQuery("Select id from details where us_t='"+u+"'and st='"+s+"' and std='"+s1+"' and divn='"+d+"'");   

        while(rsta.next()){
        d_id=rsta.getString("id");
         }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println("ddetail id"+d_id);//Print on console
        try {
            // connects to the database

            // constructs SQL statement
          //  String sql = "INSERT INTO test4 (index_qn,q_no,q_text,as,f_name,dy,at) values (?, ?, ?, ?,?,?,?)";
            String sql = "INSERT INTO question (qn,o1,o2,o3,o4,an,d_id) values (?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement statement = conn.prepareStatement(sql);

            statement.setString(1, qn);
            statement.setString(2, o1);
            statement.setString(3, o2);
            statement.setString(4, o3);
            statement.setString(5, o4);
            statement.setString(6,an;
            statement.setString(7,d_id);

            // sends the statement to the database server
            int row = statement.executeUpdate();

Here I want the d_id to pass in my next query but the d_id gives me a null value.I have put a system.out for d_id,when I check it on the console it gives me a null value.What am I doing wrong. 在这里,我希望d_id传递下一个查询,但是d_id给了我一个空值。当我在控制台上对其进行检查时,我为d_id放置了一个system.out,它给了我一个空值。我在做什么错。 When I type the same query on mysql command line,it works fine.Just on this. 当我在mysql命令行上键入相同的查询时,它工作正常。 This is a JSP project 这是一个JSP项目

It might be possible that your ResultSet is not containing any result. 您的ResultSet可能不包含任何结果。 Try to put some print statement in while loop. 尝试在while循环中放入一些打印语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM