用户名和密码的登陆
package com.lianxi; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Scanner; public class TestSign { public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/boooks","root","tiger"); Statement st=conn.createStatement(); Scanner s=new Scanner(System.in); System.out.println("用户名"); String name=s.nextLine(); System.out.println("密码"); String pwd=s.nextLine(); ResultSet rs=st.executeQuery("select * from tb_user where userName='"+name+"' and password='"+pwd+"' "); if(rs.next()){ System.out.println("登陆成功"); }else{ System.out.println("用户名或密码错误"); } rs.close(); st.close(); conn.close(); } }