我有一些正在向數據庫發送查詢的類。當查詢是在代碼中時,一切工作正常,但由於它很大,我決定把它放在一個文件中,並用緩衝讀取器讀取它,但它不工作,我總是得到這個:如何從Java中的txt文件讀取sql查詢
值java.sql.SQLException:ORA-00900:無效的SQL語句
這裏是我的查詢:
SELECT
p.first_name \"FirstName\",
p.middle_name \"MiddleName\",
p.last_name \"LastName\",
p.birth_name \"BirthName\",
p.mothers_name \"MothersName\",
p.nick_name \"NickName\",
p.username \"Username\",
p.currency_id \"Currency\",
p.preferred_language_id \"PreferredLanguage\",
p.accepts_email \"AcceptsEmail\",
p.birth_date \"BirthDate\",
p.hear_about_us \"HeardAboutUs\",
p.tax_category_id \"TaxCategory\",
p.birth_place \"BirthPlace\",
p.accepts_id_verification \"AcceptsIdentityVerification\",
p.security_prompt \"SecurityPrompt\",
p.gender_id \"Gender\",
p.tracking_campaign_name \"TrackingCampaign\",
p.accepts_sms \"AcceptsSMS\",
p.accepts_promotional_sms \"AcceptsPromotionalSMS\",
p.identification_number \"IdentificationNumber\",
p.id_verified_id \"IdentificationVerified\",
p.security_word \"SecurityWord\",
p.ident_manual_verified_until \"IdentificationManualVerified\",
p.accepts_chat \"AcceptsChat\",
p.frequent_player_level_id \"FrequentPlayerLevel\",
p.preferred_comm_channel \"PreferredCommunicationChannel\",
p.is_reward_abuser \"IsRewardAbuser\",
p.newsletter_id \"Newsletter\",
p.accepts_rewards \"AcceptsRewards\",
ci.postal_code \"PostalCode\",
ci.country_id \"Country\",
ci.region \"Region\",
ci.email \"Email\",
ci.address1 \"Address1\",
ci.address2 \"Address2\",
ci.address3 \"Address3\",
ci.phone1 \"Phone1\",
ci.phone2 \"Phone2\",
ci.city \"City\",
ci.mobile_phone \"MobilePhone\",
ci.address_state_id \"AddressVerified\"
FROM
player p
JOIN contact_info ci ON p.CONTACT_INFO_ID = ci.CONTACT_INFO_ID
JOIN player_session ps ON p.PLAYER_ID = ps.PLAYER_ID
WHERE
ps.external_client_session_id = \'$sessionID\'
這裏是我使用的代碼:
String query = "";
try{
BufferedReader bufferedReader = new BufferedReader(
new FileReader("templates\\sqlQueries\\GetPlayerDetails.txt")
);
while(bufferedReader.readLine()!=null){
query = new StringBuilder().append(query).append(bufferedReader.readLine()).toString();
}
}
catch (FileNotFoundException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
query = query.replace("$sessionID", sessionID);
我建議孩子的步驟。嘗試選擇許多字段的嘗試僅選擇一個字段。這使得麻煩更輕鬆。 –