Get the App
SLTechnology News&Howtos  ›  Database  › 

Java connects to MySQL. ATM

Shulou Source: shulou.com Published: 2022-06-01 13:33:27 10月03日 Update

Package bank;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import java.util.Scanner;public class JDBC {static Statement sc=null; static Scanner sca=new Scanner (System.in); static String username; public static void main (String [] args) throws Exception {/ / this method is to get the operating platform of the database. GetStatement (); System.out.println ("well come to bank of china"); System.out.println ("Please select what you want:" + "1. Register "+" 2. Login "); int m=sca.nextInt (); for (int jackpot;) {if (jackpot 1) {System.out.println (" Please enter a new account "); String bname=sca.next () System.out.println ("Please enter a new password"); String bpassword=sca.next (); String sql= "select * from bank where bname='" + bname+ "'"; ResultSet bq=sc.executeQuery (sql) / / query the database if (bq.next ()) {/ / determine whether the registered account System.out.println also exists in the database ("this account has been registered") } else {sql= "insert into bank (bname,bpassword) values ('" + bname+ "','" + bpassword+ "')"; int i=sc.executeUpdate (sql) / / Update the database and use I to receive the returned data if (iComple0) {System.out.println ("registered successfully") } else {System.out.println ("registration failed") } else if (jacks 2) {for (int winters 1)

Tags: Data database query input method platform success account password type amount user user name balance content withdrawal variables deposit login people Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker MariaDB Shulou Technology Apple