In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Truncate table table name
Delete all the data in the table directly. Unlike delete, this method cannot be selected using where, and can only be deleted.
Truncate table users
Java connection to the database:
Package com.edu.gkh
Import java.sql.Connection
Import java.sql.DriverManager
Import java.sql.ResultSet
Import java.sql.Statement
Import java.util.Scanner
Public class Homework {
Static Statement sc=null
Static Scanner sca=new Scanner (System.in)
Static String username
Public static void main (String [] args) throws Exception {
GetStatement ()
String name2= ""
String pwd2= ""
For (;;) {
System.out.println ("Please enter a registered account")
String name=sca.next ()
System.out.println ("Please enter password")
String pwd=sca.next ()
System.out.println ("Please enter your password again")
String pwd1=sca.next ()
If (pwd1.equals (pwd)) {
Name2=name
Pwd2=pwd
System.out.println ("registered successfully")
Break
}
Else {
System.out.println ("two passwords are not the same, please re-enter; whether to re-register yes/no")
Char regist=sca.next () .charAt (0)
If (regist=='y') {
System.out.println ("please re-enter")
}
Else if (regist=='n') {
System.out.println ("you have unregistered")
}
Else {
System.out.println ("illegal input")
}
}
}
System.out.println ("Welcome to J18 Bank")
System.out.println ("Please log in:")
System.out.println ("user name:")
Username=sca.next ()
System.out.println ("password:")
String password=sca.next ()
Int num=queryAccount (username,password)
If (num==1) {
System.out.println ("login succeeded")
For (;;) {
System.out.println ("Please select transaction type:")
System.out.println ("1, deposit 2, withdraw 3, query balance")
Int cz=sca.nextInt ()
If (cz==1) {
Cun ()
} else if (cz==2) {
Qu ()
} else if (cz==3) {
Query ()
} else {
System.out.println ("Thank you for using")
Break
}
}
} else {
System.out.println ("login failed")
}
}
Public static void cun () throws Exception {
System.out.println ("Please enter your deposit amount:")
Double money=sca.nextDouble ()
String sql= "update account set money=money+" + money
Boolean a=sc.execute (sql)
If (! a) {
System.out.println ("deposit is successful!")
}
}
Public static void qu () throws Exception {
System.out.println ("Please enter your withdrawal amount:")
Double money=sca.nextDouble ()
String sql= "update account set money=money-" + money
System.out.println (sql)
Boolean a=sc.execute (sql)
If (! a) {
System.out.println ("withdrawal successful!")
}
}
Public static int queryAccount (String username,String password) throws Exception {
String sql= "select * from account where aname='" + username+ "'and apwd='" + password+ "'"
ResultSet rs=sc.executeQuery (sql)
Int num=0
While (rs.next ()) {
Num++
}
Return num
}
Public static void query () throws Exception {
String sql= "select money from account where aname='" + username+ "'"
ResultSet rs=sc.executeQuery (sql)
Double money=0
While (rs.next ()) {
Money=rs.getDouble (1)
}
System.out.println ("your account balance:" + money)
}
Public static void getStatement () throws Exception {
Class.forName ("com.mysql.jdbc.Driver")
String url= "jdbc:mysql://localhost:3306/atm"
String username= "root"
String password= "root"
Connection c=DriverManager.getConnection (url,username,password)
Sc=c.createStatement ()
}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.