Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ResultSet rs = null;
- PreparedStatement pst = null;
- Connection con = null;
- Statement st = null;
- final String username = "root";
- final String password = "22535";
- final String url = "jdbc:mysql://localhost:3307/project";
- String search = tf.getText();
- String tot = "";
- int count = 0;
- String sql = "";
- String key="";
- for (int i = 0; i < search.length(); i++) {
- char c = search.charAt(i);
- if ((int) c >= 97 && (int) c <= 122) {
- count++;
- }
- }
- try {
- con = DriverManager.getConnection(url, username, password);
- st = con.createStatement();
- if (count > 0) {
- sql = " sELECT * FROM project.quran where AyahTranslate like '%" + search + "%'";
- } else {
- key+="+";
- for(int i=0; i<search.length(); i++){
- if(search.charAt(i)==' '){
- key+=" +";
- }else{
- key+=search.charAt(i);
- }
- }
- sql = "sELECT * FROM project.quran WHERE MATCH (ayah) AGAINST ('" +key+"'IN BOOLEAN MODE);"; // search in Arabic
- }
- ResultSet rset = st.executeQuery(sql);
- Table1.setModel(DbUtils.resultSetToTableModel(rset));
- } catch (Exception e) {
- System.out.println("Error");
- }
- try {
- con = DriverManager.getConnection(url, username, password);
- System.out.println("Connected");
- st = con.createStatement();
- if (count > 0) {
- sql = " SELECT count(*) AS TotalResult FROM project.quran where ayahtranslate like'%" + search + "%';";
- }else {
- sql = "SELECT COUNT(*) AS TotalResult FROM project.quran WHERE MATCH (ayah) against ('" +key + "' IN BOOLEAN MODE);";
- }
- ResultSet rset = st.executeQuery(sql);
- while (rset.next()) {
- tot = rset.getString("TotalResult");
- }
- tf1.setText("there are (" + tot + ") occurrences /t( " + search + ")in the Surah AL_Fatihah and Al_Baqarah.");
- System.out.println(rset);
- } catch (Exception e) {
- System.out.println("Error");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement