首页 > 其他分享 >2023.3.22每日总结

2023.3.22每日总结

时间:2023-03-22 21:44:57浏览次数:52  
标签:总结 java String 22 2023.3 Pd sql import public

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

public class Thesql {
    public Connection connect;
    public Thesql()throws Exception 
    {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/ditie";
        String username="root";
        String password="2223640185";
        connect = DriverManager.getConnection(url,username,password);
    }
    public void finalize() throws Exception
    {
        connect.close();
    }
    //线路号查询,String name = 线路名称
    public Pd chaxunxianlu(String name) throws SQLException
    {
        String sql="select * from xinxi where mingcheng='"+name+"'";
        Statement stmt = connect.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        Pd pdd = new Pd();
        while(rs.next())
        {
            pdd.mingcheng=rs.getString(2);
            String zhan="";
            int i=3;
            while(zhan!=null)
            {
                zhan=rs.getString(i);
                pdd.zhan[i-3]=zhan;
                i++;
            }
        }
        stmt.close();
        return pdd;
    }
    //站点查询,String name = 站点名称
    public Pd[] chaxunxianlu2(String zhanname) throws Exception
    {
        String[] strings=getxianname(zhanname);
        Pd[] pdd = new Pd[strings.length];
        for(int j=0;j<strings.length;j++)
        {
            pdd[j]=chaxunxianlu(strings[j]);
        }
        return pdd;
    }
    //得到线路名称,String zhanname = 站点名称 ,返回值为字符串数组(可能多条线路),返回内容为线路名称
    public String[] getxianname(String zhanname) throws SQLException
    {
        String[] strings = new String[5];
        Statement stmt = connect.createStatement();
        int num=0;
        for(int i=1;i<36;i++)
        {
            String sql="select * from xinxi where a"+i+" ='"+zhanname+"'";
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next())
            {
                String n=rs.getString(2);
                strings[num]=n;
            }
            if(strings[num]!=null)
                num++;
        }
        String[] strings2 = new String[num];
        for(int ii=0;ii<num;ii++)
            strings2[ii]=strings[ii];
        stmt.close();
        return strings2;
    }
    //起点,线,站数,换站点,线,站数,换站点,线,站数,换站点,线,站数,终点
    public String[] chaxunQiAndZhong(String qidian,String zhongdian) throws Exception 
    {
        
        if(isxiangtong(qidian, zhongdian)!=null)
        {
            String[] jieguo = new String[1];
            jieguo[0]=isxiangtong(qidian, zhongdian);
            String[] jieguo2={qidian,jieguo[0],getchangdu(jieguo[0], qidian, zhongdian)+"",zhongdian};
            return jieguo2;
        }
        else 
        {
            String[] jieguo =getbestjieguo(chaxunduoxian(qidian, zhongdian),qidian,zhongdian);
            String[] jieguo2=new String[100];
            int n =0;
            jieguo2[0]=qidian;
            jieguo2[1]=jieguo[0];
            jieguo2[2]=getchangdu(jieguo[0],qidian,gethuanzhanname(jieguo[0],jieguo[1]))+"";
            jieguo2[3]=gethuanzhanname(jieguo[0],jieguo[1]);
            for(int i=2;i<jieguo.length&&jieguo[i]!=null;i++)
            {
                jieguo2[3*i-2]=jieguo[i-1];
                jieguo2[3*i-1]=getchangdu(jieguo[i-1],gethuanzhanname(jieguo[i-2],jieguo[i-1]),gethuanzhanname(jieguo[i-1],jieguo[i]))+"";
                jieguo2[3*i]=gethuanzhanname(jieguo[i-1],jieguo[i]);
                n=i;
            }
            jieguo2[3*n+1]=jieguo[n];
            jieguo2[3*n+2]=getchangdu(jieguo[0],zhongdian,gethuanzhanname(jieguo[0],jieguo[1]))+"";
            jieguo2[3*n+3]=zhongdian;
            return jieguo2;
        }
    }
    public String[] getbestjieguo(String[][] jieguos,String qidian,String zhongdian) throws Exception
    {
        String best[] = new String[20];
        int min=1000;
        for(int i=0;i<jieguos.length&&jieguos[i][0]!=null;i++)
        {
            int num = getchangdu(jieguos[i], qidian, zhongdian);
            if(num<min)
            {
                best=jieguos[i];
                min=num;
            }
        }
        return best;
    }
    public int getchangdu(String[] strings,String qidian,String zhongdian) throws Exception
    {
        int sum=0,n=1;
        sum=getchangdu(strings[0],qidian,gethuanzhanname(strings[0],strings[1]));
        for(int i=2;i<strings.length&&strings[i]!=null;i++)
        {
            sum=sum+getchangdu(strings[i-1],gethuanzhanname(strings[i-2],strings[i-1]), gethuanzhanname(strings[i-1],strings[i]));
            n=i;
        }
        //if(n!=2)
            sum=sum+getchangdu(strings[n],zhongdian,gethuanzhanname(strings[n-1],strings[n]));
        return sum;
    }
    public int getchangdu(String xianname,String A,String B) throws Exception
    {
        Pd pd = chaxunxianlu(xianname);
        int a=0,b=0;
        for (int i=0;i<pd.zhan.length&&pd.zhan[i]!=null;i++) 
        {
            if(A.equals(pd.zhan[i]))
                a=i;
            if(B.equals(pd.zhan[i]))
                b=i;
        }
        if(a>b)
            return (a-b);
        else 
            return (b-a);
    }
    
    public String[][] chaxunduoxian(String A,String B) throws Exception 
    {
        String[] jieguo = new String[20];
        String[][] jieguos = new String[1000][20];
        int n=0;
        
        String[] strings = getxianname(A);
        for (int i=0;i<strings.length;i++) 
        {
            String[] huanzhans = gethuanzhanname(strings[i]);
            if(isxiangtong(huanzhans,B)!=null)
            {
                String string =isxiangtong(huanzhans,B);
                jieguo[0]=strings[i];
                jieguo[1]=string;
                jieguos[n]=jieguo;
                n++;
            }
            
            for(int j=0;j<huanzhans.length;j++)
            {
                String[] strings2 = getxianname(huanzhans[j]);
                for (int k=0; k<strings2.length;k++) 
                {
                    String[] huanzhans2 = gethuanzhanname(strings2[k]);
                    if(isxiangtong(huanzhans2,B)!=null)
                    {
                        String string =isxiangtong(huanzhans2,B);
                        jieguo[0]=strings[i];
                        jieguo[1]=strings2[k];
                        jieguo[2]=string;
                        jieguos[n]=jieguo;
                        n++;
                    }
                }
            }
            if(jieguos[0][0] != null)
            {
                return jieguos;
            }else {
                for(int j=0;j<huanzhans.length;j++)
                {
                    String[] strings2 = getxianname(huanzhans[j]);
                    for (int k=0; k<strings2.length;k++) 
                    {
                        String[] huanzhans2 = gethuanzhanname(strings2[k]);
                        for (int l = 0; l < huanzhans2.length; l++) 
                        {
                            String[] strings3 = getxianname(huanzhans2[l]);
                            for (int m = 0; m < strings3.length; m++) 
                            {
                                String[] huanzhans3 = gethuanzhanname(strings3[m]);
                                if(isxiangtong(huanzhans3,B)!=null)
                                {
                                    String string =isxiangtong(huanzhans3,B);
                                    jieguo[0]=strings[i];
                                    jieguo[1]=strings2[k];
                                    jieguo[2]=strings3[m];
                                    jieguo[3]=string;
                                    jieguos[n]=jieguo;
                                    n++;
                                }
                            }
                        }
                    }
                }        
            }
        }
        return jieguos;
    }
    public String isxiangtong(String A,String B) throws Exception
    {
        String[] strings = getxianname(A);
        String[] strings2 = getxianname(B);
        for(int i=0;i<strings.length;i++) 
        {
            for(int j=0;j<strings2.length;j++) 
            {
                if(strings[i].equals(strings2[j]))
                    return strings[i];
            }
        }
        return null;
    }
    public String isxiangtong(String[] A,String B) throws Exception
    {
        int n=A.length;
        for(int k=0;k<n;k++)
        {
            String[] strings = getxianname(A[k]);
            String[] strings2 = getxianname(B);
            for(int i=0;i<strings.length;i++) 
            {
                for(int j=0;j<strings2.length;j++) 
                {
                    if(strings[i].equals(strings2[j]))
                        return strings[i];
                }
            }
        }
        return null;
    }
    
    public String[] gethuanzhanname(String xianname) throws SQLException 
    {
        String sql="select * from huanzhan where xian1='"+xianname+"' or xian2='"+xianname+"'";
        Statement stmt = connect.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        String[] strings = new String[30];
        int j = 0;
        while(rs.next())
        {
            strings[j]=rs.getString(2);
            j++;
        }
        String[] strings2 = new String[j];
        for(int ii=0;ii<j;ii++)
            strings2[ii]=strings[ii];
        stmt.close();
        return strings2;
    }
    public String gethuanzhanname(String A,String B) throws Exception
    {
        String string=new String();
        String sql="select * from huanzhan where xian1='"+A+"' and xian2='"+B+"'";
        Statement stmt = connect.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        while(rs.next())
        {
            string=rs.getString(2);
        }
        if(!string.equals(""))
        {
            return string;
        }
        else {
            String sql2="select * from huanzhan where xian1='"+B+"' and xian2='"+A+"'";
            Statement stmt2 = connect.createStatement();
            ResultSet rs2 = stmt2.executeQuery(sql2);
            while(rs2.next())
            {
                string=rs2.getString(2);
            }
            if(!string.equals(""))
            {
                return string;
            }
        }
        return null;
    }
    
    
    
    
}

地铁查询的相关操作代码

 

 

标签:总结,java,String,22,2023.3,Pd,sql,import,public
From: https://www.cnblogs.com/wllovelmbforever/p/17245574.html

相关文章

  • 2023年3月22日软工日报
    今天下午写了会儿api,下午我们宿舍团建,晚上继续写那个安卓和自己的web选修作业。  cp之照: ......
  • 3.22 - 快手日常实习一面
     一、八股1.HTTPS和HTTP2.判断相等的方法、区别一共三种:==、===和Object.is() ==:双方类型不同时会强制转换。 强制转换规则:两个基础类型进行比较时,都转换成数字类......
  • 2023、03、22学习总结
    完成了app的页面设计 ......
  • 2023-03-22 顺序表基本操作
    #include<stdio.h>#include<stdlib.h>#include<stdbool.h>#defineinitsize10typedefstruct{int*data;intlength;intmaxsize;}SqList;......
  • 20201226马瑞婕《网络对抗》Exp2后门原理与实践
    目录1实验基础1.1基础知识1.1.1后门的概念常用后门工具2.实验目标3.实验环境4.实验过程4.1使用netcat获取主机操作Shell,cron启动4.1.1在主机中使用ncat-l-p1226(个人......
  • 《渗透测试》WEB攻防-ASP安全&MDB下载植入&IIS短文件名&写权限&解析 2022 Day18
    1  ➢ ASP-数据库-MDB默认下载➢ ASP-数据库-ASP后门植入连接➢ ASP-中间件-IIS短文件名探针-安全漏洞➢ ASP-中间件-IIS文件上传解析-安全漏洞➢ ASP-中......
  • flower in 3.22
    从wuha回来,累的要噶了。wuha集训总体是摆。给我印象比较深刻的是三件事:joke3579的蜜雪冰城,给BE来了一点surprise,还有昨天晚上的团建。我确实一直在根据自己的思考......
  • Dbeaver22.0.3 连线配置mysql8版本
    编辑驱动新建连接,选则mysql库选中本地的jar文件点击编辑驱动后,选中库页签,添加文件,选中本地jar包参考https://www.cnblogs.com/jinci2022/p/16525548.html......
  • 算法总结--动态规划
    声明(叠甲):鄙人水平有限,本文为作者的学习总结,仅供参考。1.动态规划介绍动态规划,英文:DynamicProgramming,简称DP,如果某一问题有很多重叠子问题,使用动态规划是最有效的......
  • 3.22总结
    <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>Inserttitleh......