首页 > 其他分享 >5.28博客

5.28博客

时间:2024-06-16 20:22:38浏览次数:15  
标签:username preparedStatement String 博客 User user sql 5.28

又是周一,那些杀不死我的还不如直接杀死我

学习内容:安卓

package com.example.app_02.utils;
import com.example.app_02.database.MySQLConnection; import com.example.app_02.entity.User; import com.example.app_02.entity.UserInfo;
public class UserDao extends MySQLConnection {     public User findUserName(String username) {         connect();         User user = null;         try {             //sql语句。我这里是根据我自己的users表的username字段来查询记录             String sql = "select * from user where username=?";             //获取用于向数据库发送sql语句的preparedStatement             preparedStatement = connection.prepareStatement(sql);             //根据账号进行查询             preparedStatement.setString(1, username);             //执行sql查询语句并返回结果集             resultSet = preparedStatement.executeQuery();             while (resultSet.next()) {                 //.next()表示指针先下一行,若有数据则返回true                 user = new User();                 user.setUsername(resultSet.getString("username"));             }         } catch (Exception e) {             e.printStackTrace();         } finally {             close();         }         return user;//若传入成功返回账号,失败则为null     }
    public User findUser(String username, String password) {         connect();         User user = null;         try {             //sql语句。我这里是根据我自己的users表的username和password字段来查询记录             String sql = "select * from user where username=? and password=?";             //获取用于向数据库发送sql语句的preparedStatement             preparedStatement = connection.prepareStatement(sql);             //根据账号和密码进行查询             preparedStatement.setString(1, username);             preparedStatement.setString(2, password);             resultSet = preparedStatement.executeQuery();             while (resultSet.next()) {                 user = new User();                 user.setUsername(resultSet.getString("username"));                 user.setPassword(resultSet.getString("password"));             }         } catch (Exception e) {             e.printStackTrace();         } finally {             close();         }         return user;//若传入成功返回账号和密码,失败则为null     }

    public int registerUser(User user) {         int value = 0;         connect();         try {             String sql = "insert into user(username,password) values(?,?)";             preparedStatement = connection.prepareStatement(sql);             //将数据插入数据库中             preparedStatement.setString(1, user.getUsername());             preparedStatement.setString(2, user.getPassword());             value = preparedStatement.executeUpdate();         } catch (Exception e) {             e.printStackTrace();         } finally {             close();         }         return value;     }
    public int updateUserStudentid(UserInfo userInfo, String username){         int value = 0;         connect();         try {             String sql = "update user set studentid=? where username=?";             preparedStatement = connection.prepareStatement(sql);             //将数据插入数据库中             preparedStatement.setString(1, userInfo.getStudentid());             preparedStatement.setString(2, username);             value = preparedStatement.executeUpdate();         } catch (Exception e) {             e.printStackTrace();         } finally {             close();         }         return value;     } }

标签:username,preparedStatement,String,博客,User,user,sql,5.28
From: https://www.cnblogs.com/zjm921/p/18251185

相关文章

  • 5.29博客
    上午计网下午建民老师的课学习内容:安卓packagecom.example.app_02.utils;importcom.example.app_02.database.MySQLConnection;importcom.example.app_02.entity.User;importcom.example.app_02.entity.UserInfo;publicclassUserInfoDaoextendsMySQLConnection{......
  • 5.30博客
    周三:python和工程数学python学习:importrequestsfrombs4importBeautifulSoupasbsimportpandasaspdfrommatplotlibimportpyplotaspltdefget_rank(url):count=0 rank=\[\] headers={    "user-agent":"Mozilla/5.0(WindowsNT10......
  • 5.14博客
    学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="wrap_content"......
  • 5.13博客
    看看日历又是周一,本来都起床了感觉尸体有点不舒服,再躺会吧学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="......
  • 5.17博客
    排球课比赛快完了,目前为止一场没输过,我感觉这跟我课脱不了关系学习内容:spring-boot注册条件安卓:<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:id="@+id/ll_item"  an......
  • 5.6博客
    过完五一假了该进入学习状态了学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="m......
  • 4.30博客
    上午计网下午建民课晚上跑步真是充实学习内容:安卓<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical&qu......
  • 2024年6月16日 18:10,cnblog博客园的第一天!!!
    终于A了P06614迷宫游戏5,原来是动态规划......点击查看代码#include<bits/stdc++.h>#definedebug(a);cout<<#a<<"="<<a<<endl;#definerep(i,a,b)for(inti=a;i<=b;i++)#definepep(i,a,b)for(inti=a;i>=b;i--)usingnamespacestd;......
  • css样式综合案例----博客园首页简单搭建
    1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<title>博客园</title>6<metaname="viewport"content="width=device-width,initial-scal......
  • 博客园入门
    一、语言:通常博客都是采用markdown语言。1.1markdown语言教程1:https://markdown.com.cn/basic-syntax/教程2:https://forum-zh.obsidian.md/t/topic/435/教程3:https://markdown.com.cn/intro.html1.2Html语言(1)markdown提供了可无缝转换为HTML的轻量级语法。对于......