我正在java上创建一个登录表单。宁静的网络服务。我已经登录并注册了。我在这里输入板号。我想根据输入的板号检索数据。我在这里只扫描板号,如果它在数据库中,但我不知道如何显示它的细节。这是我的代码。我很困惑。我不知道怎么做。
Constants.java
NSDecimalNumber
DatabaseConnection.java
package com.taxisafe.connection;
public class Constants {
public static String dbClass = "com.mysql.jdbc.Driver";
private static String dbName= "taxisafe";
public static String dbUrl = "jdbc:mysql://localhost:3306/"+dbName;
public static String dbUsername = "root";
public static String dbPassword = "";
}
JsonConstruction.java
package com.taxisafe.connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.taxisafe.objects.Objects;
public class DatabaseConnection {
@SuppressWarnings("finally")
public static Connection createConnection() throws Exception {
Connection koneksyon = null;
try {
Class.forName(Constants.dbClass);
koneksyon = DriverManager.getConnection(Constants.dbUrl, Constants.dbUsername, Constants.dbPassword);
} catch (Exception e) {
throw e;
} finally {
return koneksyon;
}
}
//CHECK FOR LOGIN
public static boolean checkUser(String username, String password) throws Exception { //checkLogin to checkUser
boolean UserRecorded = false;
Connection konek = null;
try {
try {
konek = DatabaseConnection.createConnection();
} catch (Exception e) {
e.printStackTrace();
}
Statement statement = konek.createStatement();
String code = "SELECT * FROM user WHERE username = '" + username + "' AND password=" + "'" + password + "'";
ResultSet rs = statement.executeQuery(code);
while (rs.next()) {
UserRecorded = true;
}
} catch (SQLException sqle) {
throw sqle;
} catch (Exception e) {
// TODO Auto-generated catch block
if (konek != null) {
konek.close();
}
throw e;
} finally {
if (konek != null) {
konek.close();
}
}
return UserRecorded;
}
// REGISTER USER
public static boolean registertheUser(String name, String username, String email, String password) throws SQLException, Exception { //inserUser - registertheUser
boolean insertUser = false; //insertStatus - insertUser
Connection konek = null;
try{
try{
konek = DatabaseConnection.createConnection();
}
catch (Exception e){
e.printStackTrace();
}
Statement statement = konek.createStatement();
String code = "INSERT into user(name, username, emailaddress, password) values('"+name+ "',"+"'" + username + "','"+ email + "','" + password + "')";
int dbrecord = statement.executeUpdate(code);
if (dbrecord > 0){
insertUser = true;
}
} catch (SQLException sqle){
throw sqle;
} catch (Exception e){
if (konek !=null){
konek.close();
}
throw e;
} finally{
if (konek !=null){
konek.close();
}
} return insertUser;
}
//CHECK PLATE NUMBER
public static boolean checkPlate(String platenumber) throws Exception { //checkLogin to checkUser
boolean PlateRecorded = false;
Connection konek = null;
try {
try {
konek = DatabaseConnection.createConnection();
} catch (Exception e) {
e.printStackTrace();
}
Statement statement = konek.createStatement();
String code = "SELECT * FROM taxi WHERE taxi_plate_no = '" + platenumber+ "'";
ResultSet rs = statement.executeQuery(code);
while (rs.next()) {
PlateRecorded = true;
}
} catch (SQLException sqle) {
throw sqle;
} catch (Exception e) {
// TODO Auto-generated catch block
if (konek != null) {
konek.close();
}
throw e;
} finally {
if (konek != null) {
konek.close();
}
}
return PlateRecorded;
}
}
PlateNumberCheck.java
package com.taxisafe.json;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
public class JsonConstruction {
public static boolean isNotNull(String text){
return text !=null && text.trim().length() >=0 ? true : false;
}
public static String JSONResponse(String tag, boolean status){
JSONObject object = new JSONObject();
try{
object.put("tag", tag);
object.put("status", new Boolean(status));
} catch (JSONException e){
} return object.toString();
}
public static String JSONResponse(String tag, boolean status, String errorMessage){
JSONObject object = new JSONObject();
try{
object.put("tag", tag);
object.put("status", new Boolean(status));
object.put("errorMessage", errorMessage);
} catch (JSONException e){
} return object.toString();
}
}
请帮我说明如何显示铭牌号的详细信息。