yiqianyan 2017-03-29 04:32 采纳率: 100%
浏览 1118
已采纳

Javabean+jsp+jdbc传值问题

DBUtil.java:

 package db;

import java.sql.*;


public class DBUtil {


    private static final String URL="jdbc:mysql://127.0.0.1:3306/hotel?useUnicode=true&characterEncoding=utf-8";。
    private static final String USER="root";
    private static final String PASSWORD="1234";
    private static Connection conn=null;
    static {


        try {
            Class.forName("com.mysql.jdbc.Driver");


            conn=DriverManager.getConnection(URL, USER, PASSWORD);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    public static Connection getConnection(){
        return conn;
    }

}

message_list.jsp:

 <%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.*,java.util.*,javabean.Message"%>

<%
    Message mes_temp = new Message();

    String sql_temp = "select  message_id from message ";
    String front_id_string = mes_temp.excuteTempSql(sql_temp);


    out.print(front_id_string);

%>

Message.java:

  package javabean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import db.DBUtil;

public class Message {
    private int message_id;
    private String  nickname;
    private String photo_select;
    private String qq;
    private String email;
    private String tel;
    private String content;
    private Timestamp message_addedtime;
    private String content_reply;

    private Connection conn;
    private ResultSet rs;
    private Statement stmt;

    private String front_id_string;

    public String excuteTempSql(String sql_temp){
    //sql_temp可以传进值
        //断点调试到此处时,conn为null?
        conn = DBUtil.getConnection();
        try {
            stmt = conn.createStatement();
                        //stmt为null
            rs = stmt.executeQuery(sql_temp);
            while (rs.next()) {
                front_id_string = front_id_string + rs.getInt("checkin_id") + ",";
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return front_id_string;
    }

}

问题:注释部分。

  • 写回答

2条回答 默认 最新

  • zz8zz 2017-03-29 04:47
    关注

    如果断点在此行:stmt = conn.createStatement(); stmt就是null,还没有执行么。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献