1
我想將獲取到ResultSet對象中的數據庫與存儲在屬性文件中的數據庫進行比較。如果數據庫與屬性文件的dbname匹配,它將打印xxx.I提供下面的代碼。如何將結果集對象與字符串進行比較?
public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
Properties props=new Properties();
props.load(new FileInputStream("/home/core/Desktop/Java/Sample Netbeans Projects/Project/PropStoreDb/StoreDbNameProps.properties"));
Class.forName(props.getProperty("db.driver"));
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/", "root", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("show databases");
if(rs.next()){
for(int i=1;i<=rs.getRow();i++){
if(rs.getString(i).equals(props.getProperty("db.dbname")))
{
System.out.println("xxx");
}
}
}
這裏是屬性文件
db.dbname=mydb
db.url=jdbc:mysql://localhost/mydb
db.driver=com.mysql.jdbc.Driver
代碼運行良好..謝謝你 – skd
歡迎:) – Keerthivasan