Document directory
- Description
- Database
- Query matched General Java code
- Query other elements by column name and unique identifier Username
- Complete Java File
- Application
- Inherited User Files
Description
During JDBC development, you often need to pass the value of the data in the database. For convenience, we can only pass the unique element of the value.
Then, the unique element is used to query and match other corresponding elements.
This allows you to operate on elements in the database.
In the previous project, I wrote some methods, which are summarized as follows.
Database
Query matched General Java code
/** Search match */public object matching (string SQL, string s) {getconn (); object = 0; try {stmt = Conn. createstatement (); RS = stmt.exe cutequery (SQL); If (RS. next () {object = Rs. getObject (s) ;}} catch (exception e) {e. printstacktrace ();} return object ;}
Query other elements by column name and unique identifier Username
/// ** Query match */public object userinquire (string linename) {return bdao. matching ("select * From ticker_user where username = '" + username + "'", linename );}
Complete Java File
Now, we can query other data in the database by column name.
Note the conversion of data types here.
Package COM. domain; import COM. dao. basedao; public class user_inquire extends user {basedao bdao = new basedao (); string username; Public user_inquire (string usernamesstring) {username = usernamesstring; setusername (username); setuserpassword (string) userinquire ("userpassword"); setusersex (string) userinquire ("usersex"); setpasspordid (string) userinquire ("passpordid"); setidcard (string) userinquire ("idcard"); setlanguage (string) userinquire ("language"); setphone (string) userinquire ("phone"); setmoney (float) userinquire ("money");} // ** query matching */public object userinquire (string linename) {return bdao. matching ("select * From ticker_user where username = '" + username + "'", linename);} public static void main (string [] ARGs) {user_inquire uinquire = new user_inquire ("Tom"); system. out. println (uinquire. getuserpassword (); system. out. println (uinquire. getUserName (); system. out. println (uinquire. getidcard (); system. out. println (uinquire. getlanguage (); system. out. println (uinquire. getmoney (); system. out. println (uinquire. getpasspordid (); system. out. println (uinquire. getphone (); system. out. println (uinquire. getusersex ());}}
APP instantiation:
User_inquire uinquire = new user_inquire (username );
Obtain the corresponding data:
Uinquire. Get .........
Example:
Public user_revise (string username) {super ("Eastern Airlines-[modify information] ---" + username); initcomponents (); setresizable (false); setlocation (420,260); setdefaclocloseoperation (jframe. hide_on_close); usermenus = 2; usernamestring = username; user_inquire uinquire = new user_inquire (username); jlabel12.settext (uinquire. getUserName (); jlabel13.settext (uinquire. getidcard (); If (uinquire. getusersex (). equals ("male") {jradiobutton1.setselected (true); random (false);} else {jradiobutton2.setselected (true); random (false);} jtextfield3.settext (uinquire. getpasspordid (); jtextfield4.settext (uinquire. getlanguage (); jtextfield5.settext (uinquire. getphone ());}
Inherited User Files
package com.domain;public class User {String username;String userpassword;String usersex;String passpordid;String idcard;String language;String phone;float money;String password;public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public float getMoney() {return money;}public void setMoney(float f) {this.money = f;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getUserpassword() {return userpassword;}public void setUserpassword(String userpassword) {this.userpassword = userpassword;}public String getUsersex() {return usersex;}public void setUsersex(String usersex) {this.usersex = usersex;}public String getPasspordid() {return passpordid;}public void setPasspordid(String passpordid) {this.passpordid = passpordid;}public String getIdcard() {return idcard;}public void setIdcard(String idcard) {this.idcard = idcard;}public String getLanguage() {return language;}public void setLanguage(String language) {this.language = language;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}}