实习日记day2

jdbc

1.jdbc概念

JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成。JDBC提供了一种基准,据此可以构建更高级的工具和接口,使数据库开发人员能够编写数据库应用程序。 有了JDBC,向各种关系数据发送SQL语句就是一件很容易的事。换言之,有了JDBC API,就不必为访问Sybase数据库专门写一个程序,为访问Oracle数据库又专门写一个程序,或为访问Informix数据库又编写另一个程序等等,程序员只需用JDBC API写一个程序就够了,它可向相应数据库发送SQL调用。同时,将Java语言和JDBC结合起来使程序员不必为不同的平台编写不同的应用程序,只须写一遍程序就可以让它在任何平台上运行,这也是Java语言“编写一次,处处运行”的优势。 简单地说,JDBC 可做三件事:与数据库建立连接、发送 操作数据库的语句并处理结果

2.jdbc的步骤

1).注册驱动class.forName(String driverName)
2).建立连接
Connection conn=DriverManager.getConnection(String url,String username,String password)
3).创建sql语句
4)获取statement对象
Statement state = con.createStatement();
或者PreparedStatement preStm = con.preparedStatement(sql);
5)执行sql语句
Result rs = state.executeQuery(sql);
int i = state.executeUpdate(sql);
或者
Result rs = preStm.executeQuery(sql);
int i=state.executeQuery(sql)
6)遍历结果集
while(rs.next()){
……
}
7)关闭连接
按顺序从内到外关
rs.close();
state.close();
con.close();

3.分层

以用户增删查改为例

1.dao

IUser:接口,里面放置对用户的抽象方法

package com.erha.dao;

import com.erha.model.User;

public interface IUser {
    void insertUser(User newUser) throws Exception;  // 添加用户的方法

    void deleteUser(int id) throws Exception;  // 删除用户的方法

    void updateUser(int id,User modUser) throws Exception;  // 更新用户的方法

    void selectByID(int id) throws Exception;   // 根据id查询用户

    void selectAllUser() throws  Exception;// 查询全部用户
}

2.daoimpl

userDao存放用户的增删改查

package daoimpl;

import dao.IUser;
import model.User;
import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao implements IUser {
    DBUtil db;
    Connection conn;
    String sql=null;
    PreparedStatement pstm;
    ResultSet rs=null;
   public void insertUser(User newUser) throws SQLException {
       db=new DBUtil();
       conn=db.getConn();
       sql="insert into user_table values(?,?,?)";
       pstm=conn.prepareStatement(sql);
       pstm.setString(1,newUser.getId());
       pstm.setString(2,newUser.getName());
       pstm.setString(3,newUser.getPassword());
       pstm.executeUpdate();
       db.Close(pstm,rs,conn);
   }
   public void deleteUser(String id) throws SQLException {
       db=new DBUtil();
       conn=db.getConn();
       sql="delete from user_table where id=?";
       pstm=conn.prepareStatement(sql);
       pstm.setString(1,id);
       pstm.executeUpdate();
       db.Close(pstm,rs,conn);
   }
    public void selectAll() throws SQLException {
        db=new DBUtil();
        conn=db.getConn();
        sql="select*from user_table";
        pstm=conn.prepareStatement(sql);
        rs=pstm.executeQuery();
        while(rs.next()){
            System.out.println(rs.getString(1)+rs.getString(2)+rs.getString(3));
        }
        db.Close(pstm,rs,conn);



    }
    public void selectById(String id) throws SQLException {
        db=new DBUtil();
        conn=db.getConn();
        sql="select*from user_table where id=?";
        pstm=conn.prepareStatement(sql);
        pstm.setString(1,id);
        rs=pstm.executeQuery();
        while(rs.next()){
            System.out.println(rs.getString(1)+rs.getString(2)+rs.getString(3));
        }
        db.Close(pstm,rs,conn);
    }
    public void changePassword(String id,String password) throws SQLException {
        db=new DBUtil();
        conn=db.getConn();
        sql="update user_table set password=? where id=?";
        pstm=conn.prepareStatement(sql);
        pstm.setString(1,password);
        pstm.setString(2,id);
        pstm.executeUpdate();
        db.Close(pstm,rs,conn);
    }
    public boolean getHaveUser(String name ,String password) throws SQLException {
       db=new DBUtil();
       conn=db.getConn();
       sql="select*from user_table where name=? and password=?";
       pstm=conn.prepareStatement(sql);
       pstm.setString(1,name);
       pstm.setString(2,password);
       rs=pstm.executeQuery();
       if(!rs.next()){
           db.Close(pstm,rs,conn);
           return false;

       }
        db.Close(pstm,rs,conn);
       return true;

    }
}

3.model

user:定义用户的属性

package model;

public  class User {
    private String  id;
    private String name;
    private String password;
    public User(){

    }

    public User(String id,String name,String password){
        this.id=id;
        this.name=name;
        this.password=password;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

4.Util

DBUtil:
连接数据库关闭数据库

package util;

import java.sql.*;

public class DBUtil {
    private String id;
    private String name;
    private String password;
    public Connection getConn() {
        Connection conn=null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
        }catch(Exception e){
            System.out.println("数据库连接失败!");
            e.printStackTrace();
        }
        return conn;

    }
    public void Close(PreparedStatement psmt, ResultSet rs, Connection conn){
        try{
            if(rs!=null){
                rs.close();
            }
            if(psmt!=null){
                psmt.close();
            }
            if(conn!=null){
                conn.close();
            }
        }catch(Exception e){
            System.out.println("数据库关闭失败!");
        }
    }
}

UserUtil:
定义用户的一些输入

package util;

import model.User;

import java.util.Scanner;

public class UserUtil {

    Scanner sc=new Scanner(System.in);
    public User getUser(){
        User user=new User();
        System.out.println("请输入用户学号:");
        user.setId(sc.nextLine());
        System.out.println("请输入用户姓名:");
        user.setName(sc.nextLine());
        System.out.println("请输入用户密码:");
        user.setPassword(sc.nextLine());
        return user;
    }
    public String getId(){
        System.out.println("请输入用户的id");
        String id=sc.nextLine();
        return id;
    }
}

5.service

定义登录主功能

package Service;

import daoimpl.UserDao;
import model.User;
import util.UserUtil;

import java.sql.SQLException;
import java.util.Scanner;

public class UserService {
    UserDao ud;
    Scanner sc;
    UserUtil ut;

    public boolean userLogin() throws SQLException {
        ud = new UserDao();
        sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String name = sc.nextLine();
        System.out.println("请输入密码:");
        String password = sc.nextLine();
        if (!ud.getHaveUser(name, password)) {
            System.out.println("登录失败!用户名或则密码错误");
            return false;
        }
        userMenu();
        return true;
    }

    public void userMenu() throws SQLException {
        while (true) {
            System.out.println("请选择功能");
            System.out.print("1.增加用户\n" + "2.删除用户\n" + "3.查询所有用户信息\n" + "4.查询某一用户信息\n" + "5.修改密码\n");
            int choose = sc.nextInt();
            sc = new Scanner(System.in);
            switch (choose) {
                case 1:
                    ut = new UserUtil();
                    User newUser = ut.getUser();
                    ud.insertUser(newUser);
                    break;
                case 2:
                    System.out.println("请输入删除的学号:");
                    String id = sc.nextLine();
                    ud.deleteUser(id);
                    break;

                case 3:
                    ud.selectAll();
                    break;

                case 4:
                    System.out.println("请输入查询的学号:");
                    String id1 = sc.nextLine();
                    ud.selectById(id1);
                    break;
                case 5:
                    System.out.println("请输入查询的学号:");
                    String id2 = sc.nextLine();
                    System.out.println("请新的密码:");
                    sc=new Scanner(System.in);
                    String password=sc.nextLine();
                    ud.changePassword(id2,password );
                    break;
            }


        }
    }
}

6.再定义一个类,调用userService即可

4.IDEA的优化

下列图片转自实习老师
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

以下是对提供的参考资料的总结,按照要求结构化多个要点分条输出: 4G/5G无线网络优化与网规案例分析: NSA站点下终端掉4G问题:部分用户反馈NSA终端频繁掉4G,主要因终端主动发起SCGfail导致。分析显示,在信号较好的环境下,终端可能因节能、过热保护等原因主动释放连接。解决方案建议终端侧进行分析处理,尝试关闭节电开关等。 RSSI算法识别天馈遮挡:通过计算RSSI平均值及差值识别天馈遮挡,差值大于3dB则认定有遮挡。不同设备分组规则不同,如64T和32T。此方法可有效帮助现场人员识别因环境变化引起的网络问题。 5G 160M组网小区CA不生效:某5G站点开启100M+60M CA功能后,测试发现UE无法正常使用CA功能。问题原因在于CA频点集标识配置错误,修正后测试正常。 5G网络优化与策略: CCE映射方式优化:针对诺基亚站点覆盖农村区域,通过优化CCE资源映射方式(交织、非交织),提升RRC连接建立成功率和无线接通率。非交织方式相比交织方式有显著提升。 5G AAU两扇区组网:与三扇区组网相比,AAU两扇区组网在RSRP、SINR、下载速率和上传速率上表现不同,需根据具体场景选择适合的组网方式。 5G语音解决方案:包括沿用4G语音解决方案、EPS Fallback方案和VoNR方案。不同方案适用于不同的5G组网策略,如NSA和SA,并影响语音连续性和网络覆盖。 4G网络优化与资源利用: 4G室分设备利旧:面对4G网络投资压减与资源需求矛盾,提出利旧多维度调优策略,包括资源整合、统筹调配既有资源,以满足新增需求和提质增效。 宏站RRU设备1托N射灯:针对5G深度覆盖需求,研究使用宏站AAU结合1托N射灯方案,快速便捷地开通5G站点,提升深度覆盖能力。 基站与流程管理: 爱立信LTE基站邻区添加流程:未提供具体内容,但通常涉及邻区规划、参数配置、测试验证等步骤,以确保基站间顺畅切换和覆盖连续性。 网络规划与策略: 新高铁跨海大桥覆盖方案试点:虽未提供详细内容,但可推测涉及高铁跨海大桥区域的4G/5G网络覆盖规划,需考虑信号穿透、移动性管理、网络容量等因素。 总结: 提供的参考资料涵盖了4G/5G无线网络优化、网规案例分析、网络优化策略、资源利用、基站管理等多个方面。 通过具体案例分析,展示了无线网络优化中的常见问题及解决方案,如NSA终端掉4G、RSSI识别天馈遮挡、CA不生效等。 强调了5G网络优化与策略的重要性,包括CCE映射方式优化、5G语音解决方案、AAU扇区组网选择等。 提出了4G网络优化与资源利用的策略,如室分设备利旧、宏站RRU设备1托N射灯等。 基站与流程管理方面,提到了爱立信LTE基站邻区添加流程,但未给出具体细节。 新高铁跨海大桥覆盖方案试点展示了特殊场景下的网络规划需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值