首页 > 其他分享 >3.26web和android端地铁查询开发学习总结

3.26web和android端地铁查询开发学习总结

时间:2023-03-26 21:24:54浏览次数:35  
标签:web String Connection static 3.26 android null find conn

web端的思想在前面已经写了,Android端的思想

跟web端差不多少,其中不一样的就是连接MySQL

数据库,其要求的jar包是5版本左右的,而且还涉及

到线程的问题,在连接MySQL的时候要另外启动一个

线程进行连接,主要思想上没啥改变,就是每次每种

查询要加一个button并且对应Onclick事件,在这个事件

里面启动一个新的线程。

我的队友是江新兵,我俩在此次开发中收获了很多。

 

 

 

 

 

 

package mysqll;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBOpenHelper {
    private final static String driver = "com.mysql.jdbc.Driver";
    private final static String url = "jdbc:mysql://10.99.121.251/kebiao?useUnicode=true&characterEncoding=UTF-8&useSSL=false";//
    private final static String username = "root";
    private final static String password = "123456";

    Connection conn=null;
    Statement st=null;
    ResultSet rs=null;

    static {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            System.out.println("加载驱动错误");
        }
    }


    //2. 获取连接
    public static Connection getConnect() throws Exception {
        return DriverManager.getConnection(url, username, password);
    }

    //3. 释放连接资源

    public static void release(Connection conn, Statement st, ResultSet rs) throws Exception {
        if (rs != null) {
            rs.close();
        }
        if (st != null) {
            st.close();
        }
        if (conn != null) {
            conn.close();
        }

    }
/*private static String diver = "com.mysql.jdbc.Driver";
    //加入utf-8是为了后面往表中输入中文,表中不会出现乱码的情况
    private static String url = "jdbc:mysql://10.99.117.52we?characterEncoding=utf-8";
    private static String user = "root";//用户名
    private static String password = "hzl02096";//密码
    *//*
     * 连接数据库
     * *//*
    public static Connection getConn(){
        Connection conn = null;
        try {
            Class.forName(diver);
            conn = (Connection) DriverManager.getConnection(url,user,password);//获取连接
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }*/

}

  public int findstationsatrole(String roles) throws Exception {
        Connection conn = null;
        Statement state = null;
        ResultSet find = null;
        int stationsnumber = 0;
        try {
            conn = DBOpenHelper.getConnect();
            state = conn.createStatement();
            roles = roles + "号线";
            String sql = "SELECT  sname FROM biejing_subway"
                    + " WHERE sline='" + roles + "';";
            find = state.executeQuery(sql);

            stationsnumber = -1;

            while (find.next()) {
                stationsnumber++;
                onrolestation[stationsnumber] = new String();
                onrolestation[stationsnumber] = find.getString(1);
            }
            if (stationsnumber != -1) {
                for (int i = 0; i <= (stationsnumber / 2) + 1; i++) {
                    stationss = stationss + onrolestation[i]+" , ";
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBOpenHelper.release(conn, state, find);
        }

        return stationsnumber;
    }



    public int findrolesatstation(String stations) throws Exception {
        Connection conn = null;
        Statement state = null;
        ResultSet find = null;
        int stationsnumber = 0;
        int rolesnumber = 0;
        try {
            conn = DBOpenHelper.getConnect();
            state = conn.createStatement();
            String sql = "SELECT  sline FROM biejing_subway"
                    + " WHERE sname='" + stations + "';";
            find = state.executeQuery(sql);

            rolesnumber = -1;
            int zhuanhuan = 0;
            while (find.next()) {
                if (zhuanhuan % 2 == 0) {
                    rolesnumber++;
                    onstationatroles[rolesnumber] = new String();
                    onstationatroles[rolesnumber] = find.getString(1);

                }
                System.out.print(rolesnumber);
                zhuanhuan++;
            }

            if(rolesnumber!=-1) {
                for (int i = 0; i <= rolesnumber; i++) {
                    rolessss = rolessss + onstationatroles[i] + " , ";
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBOpenHelper.release(conn, state, find);
        }

        return rolesnumber;
    }

标签:web,String,Connection,static,3.26,android,null,find,conn
From: https://www.cnblogs.com/-GYP/p/17259566.html

相关文章

  • 3.26全部完成android和web端的地铁查询系统
    web端的思想在前面已经写了,Android端的思想跟web端差不多少,其中不一样的就是连接MySQL数据库,其要求的jar包是5版本左右的,而且还涉及到线程的问题,在连接MySQL的时候要另......
  • 去中心化组件共享方案 —— Webpack Module Federation(模块联邦)
    在大型应用中,我们可能会对其进行拆分,分成容器、主应用和多个子应用,使拆分后的应用独立开发与部署,更加容易维护。但无论是微应用、公共模块应用,都需要放到容器中才能使用。......
  • 将纸壳CMS通知通过WebHook发送到钉钉
    纸壳CMS支持将评论、留言、表单提交、订阅等通知,通过WebHook发送到第三方平台,比如钉钉。创建钉钉WebHook需要在钉钉群中创建自定义机器人,具体方法可以参考钉钉的官方文档......
  • web前端框架——Vue的特性
    目录前言: 一.vue二.特性1.轻量级2.数据绑定3.指令4.插件三.比较Angular、React、Vue框架之间的比较1.AngularAngular的优点:2.ReactReact的优点:3.vue3.Vue的优点:前言: ......
  • Android简单集成高德地图API
    首先进入高德官网  高德开放平台|高德地图API(amap.com)  注册登录完成之后创建新应用  点击之后呈现如下页面:  Key的名称随便起,主要是提交后会有一个......
  • IntelliWeb 中嵌入Silverlight/Flash方法
       简介:intelliWeb是基于构件、Ajax、RichClient技术的J2EE应用快速开发平台。   嵌入Silverlight/Flash方法很简单,把ActiveX放到e:Page里面就可以了  下面我......
  • 基于Agora SDK实现Android端的声动互娱(四)——美声、变声和人声
    近几年诈骗罪成为了我国刑事犯罪的第一大罪名,在网络上勾引你裸聊的“小姐姐”很可能是抠脚大汉利用美声软件假扮的。美声和人声在社交娱乐场景中可以为增添场景的趣味性并提......
  • Android平板替代FTP服务器实战
     完了,公司的FTP服务器挂了。 挂了就挂了,不需要我等草民去管。 当务之急就是找台机器去顶替下。 问题是买台服务器要钱。 好在公司源代码和开发工具不大,自己做个F......
  • 在Android Studio中输入汉语
    之前一直以为在AndroidStudio中只能使用英文输入,今天发现它可以使用汉语输入只要把语言更改成简体中文就好了 我使用的是pixe2API30 设置之后要用英文模式拼写......
  • 什么是 Web 应用程序的 synthetic monitor
    Web应用程序的syntheticmonitor是一种监测工具,用于模拟用户与Web应用程序交互的过程,并监测系统的响应时间和性能表现。该工具使用自动化脚本来模拟用户行为,例如页面......