package com.example.leudaemialikeme.Dao;

import android.util.Log;

import com.example.leudaemialikeme.Utils.DBUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class QuestionDao {

    public boolean qSelect()throws Exception{
        Connection conn=null;
        Statement state=null;
        ResultSet rs=null;
        try{
            conn= DBUtils.getConnect();
            state=conn.createStatement();
            String sql="select uid=1 from Question";
            rs=state.executeQuery(sql);
            while (rs.next()){
                Log.e("MYSQL","连接成功：uid"+rs.getString(1));
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DBUtils.release(conn,state,rs);
        }
        return true;
    }

    public boolean qInsert(int uid,String title,
                           String content,String time,int follow,int answer,int browse
    )throws Exception{
        Connection conn=null;
        Statement state=null;
        ResultSet rs=null;
        try{
            conn= DBUtils.getConnect();
            state=conn.createStatement();
            String sql="insert question(uid,qtitle,qcontent,qtime,qfollowNum,qanswerNum,qbrowseNum) values('"+
                    uid+"','"+title+"','"+content+"','"+time+"','"+follow+"','"+answer+"','"+browse+"')";
            state.execute(sql);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DBUtils.release(conn,state,rs);
        }
        return true;
    }
}


