如何编写存储过程以获取官员报告的犯罪数量并在Java JDBC中使用它?

时间:2018-03-12 00:54:58

标签: mysql-workbench

此过程将 officer_id 作为输入,并返回该人员报告的犯罪数量作为输出。在MySQL中测试此过程。 Schema crime_officers(crime_id,officer_id都是主键)

我目前的代码是: 分隔符// 创建过程getNumber( 在officer_id int(8)中, out crime_cnt int ) 开始 选择officer_id,将(crime_id)计为crime_cnt 来自crime_officers group by officer_id; 端//

Java:我已经建立了连接和驱动程序 Java中给出的代码:

public void findCrimeCounts() throws SQLException
    {
        System.out.println("******** Query 7 ********");    
        InputStreamReader istream = new InputStreamReader(System.in) ;
      BufferedReader bufRead = new BufferedReader(istream) ;

        try{
            System.out.println("Please enter the officer_id for the query: ");

           System.out.println("Officer " +id+" has reported "+cnt+" crimes.");
       }            
        catch (IOException err) {
            System.out.println("Error reading line");
           }
    }

1 个答案:

答案 0 :(得分:0)

表crime_officers,列有officer_id和crime_id,也许是犯罪 也许详细说明所有列,但这就是我的想法

$cn=mysqli_connect("localhost","your username","","yourdbname");

$s= "SELECT * FROM `crime_officers`";

$result=mysqli_query($cn,$s);

$r=mysqli_num_rows($result);

echo $r;