第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何根據(jù)我的情況在 JDBC 中正確使用 ResultSet 類?

如何根據(jù)我的情況在 JDBC 中正確使用 ResultSet 類?

翻閱古今 2021-07-19 16:17:21
我正在將客戶添加到數(shù)據(jù)庫(kù)中,但前提是數(shù)據(jù)庫(kù)中沒(méi)有其他 CustomerID 與我剛剛輸入的 CustomerID 相同。我在 Eclipse 中使用 JDBC 和 MySQL 來(lái)執(zhí)行此操作。有人能告訴我我的 while 循環(huán)是否正確設(shè)置來(lái)實(shí)現(xiàn)這一點(diǎn)嗎?我得到了很多奇怪的輸出,所以它可能不是。我已經(jīng)在網(wǎng)上環(huán)顧了幾個(gè)小時(shí),但我無(wú)法讓它工作。我怎樣才能正確地做到這一點(diǎn)?我的一段代碼如下所示。public void addCust() {    String url = "jdbc:mysql://localhost:3306/northwind?useSSL=false&serverTimezone=EST";    String username = "root";    String password = "<password>";    String tempCustID, custID, comp, contName, contTitle, addr, city, reg, postCode, country, phone, fax;    System.out.println("Loading driver...");    try {        Class.forName("com.mysql.cj.jdbc.Driver");        System.out.println("Driver loaded!");    }catch (ClassNotFoundException e) {        throw new IllegalStateException("Cannot find the driver in the classpath!", e);    }    System.out.println("Connecting database...");    try {        Connection mycon = DriverManager.getConnection(url, username, password);        System.out.println("Database connected!");        Scanner keyboard1 = new Scanner(System.in);        System.out.println("Enter 5 letters to identify the customer as.");        tempCustID = keyboard1.nextLine();        custID = tempCustID.toUpperCase();        /**        if(custID == "") {            System.out.println("Must enter a value.");            addCust();        }        */        PreparedStatement stat = mycon.prepareStatement("SELECT CustomerID FROM customers");        ResultSet cust = stat.executeQuery();        while(cust.next()) {            String customerID = cust.getString("CustomerID");            if(custID == customerID) {                System.out.println("Customer ID already exists. Please enter a different sequence of 5 letters to identify the customer as.");                options();            }        }
查看完整描述

1 回答

?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊

使用equals方法比較字符串而不是“==”


查看完整回答
反對(duì) 回復(fù) 2021-07-29
  • 1 回答
  • 0 關(guān)注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)