search engine in java

Reply

Join Date: Jul 2009
Posts: 8
Reputation: karamjeet2004 is an unknown quantity at this point 
Solved Threads: 0
karamjeet2004 karamjeet2004 is offline Offline
Newbie Poster

search engine in java

 
0
  #1
Jul 2nd, 2009
Hi I am making some kind of search engine in java.In which i want to search initials from database(ms access)
suppose to search united states of america
we type usoa
so how can i do that
from where to i start
can anybody plz.........
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: search engine in java

 
0
  #2
Jul 3rd, 2009
karamjeet2004,

You have to use java.sql package and sql select statement with pattern (%,?) and where caluse.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 19
Reputation: oliver_lundag has a little shameless behaviour in the past 
Solved Threads: 0
oliver_lundag oliver_lundag is offline Offline
Newbie Poster

Re: search engine in java

 
-1
  #3
Jul 16th, 2009
  1. package src.maintenance.accntMasterfile;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Point;
  6. import java.awt.Rectangle;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.KeyAdapter;
  10. import java.awt.event.KeyEvent;
  11. import java.sql.ResultSet;
  12. import java.sql.Statement;
  13.  
  14. import javax.swing.BorderFactory;
  15. import javax.swing.InputMap;
  16. import javax.swing.JButton;
  17. import javax.swing.JComboBox;
  18. import javax.swing.JDialog;
  19. import javax.swing.JLabel;
  20. import javax.swing.JPanel;
  21. import javax.swing.JScrollPane;
  22. import javax.swing.JTable;
  23. import javax.swing.JTextField;
  24. import javax.swing.KeyStroke;
  25. import javax.swing.Timer;
  26. import javax.swing.table.DefaultTableCellRenderer;
  27. import javax.swing.table.DefaultTableModel;
  28. import javax.swing.table.TableCellRenderer;
  29.  
  30. import src.maintenance.DBConn.DBConnect;
  31. import src.maintenance.Functions.ActionCursor;
  32. import src.maintenance.Functions.Message;
  33. import src.maintenance.Functions.MyField;
  34. import src.maintenance.core.mainform;
  35.  
  36. public class EditaccntMasterfile extends JDialog {
  37.  
  38. /**
  39. *
  40. */
  41. /**
  42. * @Author: Oliver D. Lundag
  43. * @Title: Maintenance for Account Master File
  44. *
  45. * @oliver_lundag@yahoo.com
  46. */
  47. private static final long serialVersionUID = 1L;
  48.  
  49. private JPanel jContentPane = null;
  50.  
  51. private JLabel jlSearch = null;
  52.  
  53. private MyField jtSearch = null;
  54. private JLabel jlSearchby = null;
  55.  
  56. private JButton jExit = null;
  57.  
  58. static JComboBox jcbsearchBy = null;
  59.  
  60. private JScrollPane jScrollPane = null;
  61. private JTable jTable = null;
  62. private DefaultTableModel tableSearch = new DefaultTableModel(new String[][]{},new String[]{"No.", "accntcode", "bankcode", "accntnumber","accntdesc"});
  63. private DefaultTableModel tempTable = new DefaultTableModel(new String[][]{},new String[]{"No.","accntcode", "bankcode", "accntnumber","accntdesc"});
  64. private String defaultQuery = "select accntcode, bankcode, accntnumber,accntdesc from accntmasterfile order by accntcode desc ";
  65. private String xString = "";
  66. private Timer sTimer = null;
  67. private int timer = 0;
  68.  
  69. public EditaccntMasterfile(){
  70. super(mainform.frame);
  71. this.setDefaultCloseOperation(EditaccntMasterfile.DO_NOTHING_ON_CLOSE);
  72. initialize();
  73. }
  74.  
  75. private void initialize(){
  76. this.setSize(500, 450);
  77. this.setTitle("Account Master File");
  78. this.setLocationRelativeTo(null);
  79. this.setContentPane(getJContentPane());
  80. this.setVisible(true);
  81. }
  82.  
  83. private JPanel getJContentPane() {
  84. if (jContentPane == null) {
  85.  
  86. jlSearchby = new JLabel();
  87. jlSearchby.setText("Search by:");
  88. jlSearchby.setSize(new Dimension(110, 20));
  89. jlSearchby.setLocation(new Point(15, 340));
  90.  
  91. jlSearch = new JLabel();
  92. jlSearch.setText("Search:");
  93. jlSearch.setSize(new Dimension(110, 20));
  94. jlSearch.setLocation(new Point(15, 380));
  95. }
  96. jContentPane = new JPanel();
  97. jContentPane.setLayout(null);
  98.  
  99. jContentPane.add(jlSearchby,null);
  100. jContentPane.add(jlSearch,null);
  101. jContentPane.add(getjcbsearchBy(), null);
  102. jContentPane.add(getJtSearch(), null);
  103. jContentPane.add(getjExit() , null);
  104. jContentPane.add(getJScrollPane(),null);
  105.  
  106. return jContentPane;
  107. }
  108.  
  109. private JComboBox getjcbsearchBy(){
  110. if(jcbsearchBy == null){
  111. jcbsearchBy = new JComboBox();
  112. jcbsearchBy.setSize(new Dimension(150, 20));
  113. jcbsearchBy.setLocation(new Point(100, 340));
  114. jcbsearchBy.addItem("Account Code");
  115. jcbsearchBy.addItem("Bank Code");
  116. jcbsearchBy.addItem("Account Number");
  117. jcbsearchBy.addItem("Account Desc");
  118. jcbsearchBy.addActionListener(new ActionListener(){
  119. public void actionPerformed(ActionEvent arg0) {
  120. try{
  121. jTable.setRowSelectionInterval(0, 0);
  122. jTable.grabFocus();
  123. if (jcbsearchBy.getSelectedIndex() == 0){
  124. jtSearch.setText("");
  125. jtSearch.grabFocus();
  126. }
  127. else if (jcbsearchBy.getSelectedIndex() == 1){
  128. jtSearch.setText("");
  129. jtSearch.grabFocus();
  130. }
  131.  
  132. else if (jcbsearchBy.getSelectedIndex() == 2){
  133. jtSearch.setText("");
  134. jtSearch.grabFocus();
  135. }
  136.  
  137. else if (jcbsearchBy.getSelectedIndex() == 3){
  138. jtSearch.setText("");
  139. jtSearch.grabFocus();
  140. }
  141. }catch (IllegalArgumentException e) {}
  142. }
  143. });
  144. }
  145. return jcbsearchBy;
  146. }
  147.  
  148. private JTextField getJtSearch() {
  149. if (jtSearch == null) {
  150. jtSearch = new MyField(true,20);
  151. jtSearch.setLocation(new Point(100, 380));
  152. jtSearch.setSize(new Dimension(150, 20));
  153. jtSearch.addKeyListener(new KeyAdapter(){
  154. @SuppressWarnings("static-access")
  155. public void keyReleased(KeyEvent e){
  156. InputMap IMP = jtSearch.getInputMap(jtSearch.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
  157. KeyStroke ent = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
  158. IMP.put(ent, "none");
  159.  
  160. if (e.getKeyCode() == 10){
  161. setTable(jtSearch.getText().trim());
  162. if (jTable.getRowCount()==0){
  163. Message.messageInfo("No record found.");
  164. System.out.println("Walang record");
  165. }
  166. timer = 0;
  167. }
  168.  
  169. }
  170. });
  171. }
  172. return jtSearch;
  173. }
  174.  
  175. private JButton getjExit() {
  176. if (jExit == null) {
  177. jExit = new JButton();
  178. jExit.setBounds(new Rectangle(380, 380, 100, 20));
  179. jExit.setMnemonic(KeyEvent.VK_S);
  180. jExit.setText("Cancel");
  181. jExit.addActionListener(new java.awt.event.ActionListener() {
  182. public void actionPerformed(java.awt.event.ActionEvent e) {
  183. if (jExit.getText().toString().equalsIgnoreCase("Cancel") == true){
  184. try{
  185. Cancel();
  186. dispose();
  187. }catch(NullPointerException e1){
  188. }
  189. }
  190. }
  191. });
  192. }
  193. return jExit;
  194. }
  195.  
  196. private JScrollPane getJScrollPane() {
  197. if (jScrollPane == null) {
  198. jScrollPane = new JScrollPane();
  199. jScrollPane.setBounds(new Rectangle(10, 10, 470, 300));
  200. jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  201. jScrollPane.setViewportView(getJTable());
  202. jScrollPane.setVisible(true);
  203. }
  204. return jScrollPane;
  205. }
  206.  
  207. private JTable getJTable() {
  208. if (jTable == null) {
  209. jTable = new JTable(tableSearch){
  210. public boolean isCellEditable(int irows, int icols){
  211. return false;
  212. }
  213. };
  214.  
  215. TableCellRenderer renderer = new Renderer();
  216. jTable.setDefaultRenderer(Object.class,renderer);
  217.  
  218. jTable.setSelectionMode(0);
  219. jTable.getTableHeader().setResizingAllowed(false);
  220. jTable.getTableHeader().setReorderingAllowed(false);
  221.  
  222. jTable.getColumnModel().getColumn(0).setMinWidth(0);
  223. jTable.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
  224. jTable.getColumnModel().getColumn(1).setMinWidth(80);
  225. jTable.getTableHeader().getColumnModel().getColumn(1).setMaxWidth(80);
  226. jTable.getColumnModel().getColumn(2).setMinWidth(140);
  227. jTable.getTableHeader().getColumnModel().getColumn(2).setMaxWidth(140);
  228. jTable.getColumnModel().getColumn(3).setMinWidth(80);
  229. jTable.getTableHeader().getColumnModel().getColumn(3).setMaxWidth(80);
  230. jTable.getColumnModel().getColumn(4).setMinWidth(150);
  231. jTable.getTableHeader().getColumnModel().getColumn(4).setMaxWidth(150);
  232.  
  233. jTable.getColumnModel().getColumn(1).setHeaderValue("Account Code");
  234. jTable.getColumnModel().getColumn(2).setHeaderValue("Bank Code");
  235. jTable.getColumnModel().getColumn(3).setHeaderValue("Account No.");
  236. jTable.getColumnModel().getColumn(4).setHeaderValue("Account Description");
  237.  
  238. jTable.addKeyListener(new KeyAdapter(){
  239. public void keyPressed(KeyEvent e){
  240. InputMap IMP = jTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
  241. KeyStroke ent = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
  242. IMP.put(ent, "none");
  243.  
  244. if (e.getKeyCode() == 10){
  245. if (xString.toString().trim().length() == 0){
  246. for (int i = 0; i < tempTable.getRowCount(); i++){
  247. if (jcbsearchBy.getSelectedIndex() == 0){
  248. if (tempTable.getValueAt(i, 1).toString().equalsIgnoreCase(jTable.getValueAt(jTable.getSelectedRow(), 1).toString())){
  249. accntMasterfile.xRecordE = Integer.parseInt(tempTable.getValueAt(i, 0).toString());
  250. break;
  251. }
  252. }else if (jcbsearchBy.getSelectedIndex() == 1){
  253. if (tempTable.getValueAt(i, 2).toString().equalsIgnoreCase(jTable.getValueAt(jTable.getSelectedRow(), 2).toString())){
  254. accntMasterfile.xRecordE = Integer.parseInt(tempTable.getValueAt(i, 0).toString());
  255. break;
  256. }
  257. }else if (jcbsearchBy.getSelectedIndex() == 2){
  258. if (tempTable.getValueAt(i, 3).toString().equalsIgnoreCase(jTable.getValueAt(jTable.getSelectedRow(), 3).toString())){
  259. accntMasterfile.xRecordE = Integer.parseInt(tempTable.getValueAt(i, 0).toString());
  260. break;
  261. }
  262. }else if (jcbsearchBy.getSelectedIndex() == 3){
  263. if (tempTable.getValueAt(i, 4).toString().equalsIgnoreCase(jTable.getValueAt(jTable.getSelectedRow(), 4).toString())){
  264. accntMasterfile.xRecordE = Integer.parseInt(tempTable.getValueAt(i, 0).toString());
  265. break;
  266. }
  267. }
  268. }
  269. accntMasterfile.getRecordE();
  270. setenabledUpdate();
  271. dispose();
  272. }
  273.  
  274.  
  275. }else{
  276. if ((e.getKeyCode() > 65 && e.getKeyCode() < 90) || (e.getKeyCode() > 96 && e.getKeyCode() < 105)){
  277. char[] keyChar ={ e.getKeyChar()};
  278. String x = new String(keyChar);
  279. xString = (xString+x);
  280. setTable(xString);
  281. timer = 0;
  282. }
  283. }
  284. }
  285. });
  286. setTable();
  287. setTimer();
  288. }
  289. return jTable;
  290. }
  291.  
  292. private void setTimer(){
  293. sTimer = new Timer (500,new ActionListener(){
  294. public void actionPerformed(ActionEvent arg0) {
  295. timer++;
  296. if (timer == 3){
  297. xString = "";
  298. }
  299. }
  300. });
  301. sTimer.start();
  302. }
  303.  
  304. private class Renderer extends DefaultTableCellRenderer{
  305. private static final long serialVersionUID = 1L;
  306.  
  307. public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
  308. {
  309. super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  310. if (column == 4)setHorizontalAlignment(LEFT);
  311. if (column == 3)setHorizontalAlignment(LEFT);
  312. if (column == 2)setHorizontalAlignment(LEFT);
  313. if (column == 1)setHorizontalAlignment(LEFT);
  314. setBorder(BorderFactory.createLineBorder(getBackground(), 1));
  315. return this;
  316. }
  317. }
  318.  
  319. private void setTable(String like){
  320. ActionCursor actionCursor = new ActionCursor();
  321. try {
  322. boolean ok = false;
  323. String likeQuery = "";
  324. if (jcbsearchBy.getSelectedIndex() == 0){
  325. likeQuery = "select " +
  326. "accntcode, bankcode, accntnumber, accntdesc " +
  327. "from accntmasterfile " +
  328. "where " +
  329. "accntcode like '"+like.trim()+"%' " +
  330. "order by accntcode ";
  331. }else if (jcbsearchBy.getSelectedIndex() == 1){
  332. likeQuery = "select " +
  333. "accntcode, bankcode, accntnumber, accntdesc " +
  334. "from accntmasterfile " +
  335. "where " +
  336. "bankcode like '"+like.trim()+"%' " +
  337. "order by accntcode ";
  338. }else if (jcbsearchBy.getSelectedIndex() == 2){
  339. likeQuery = "select " +
  340. "accntcode, bankcode, accntnumber, accntdesc " +
  341. "from accntmasterfile " +
  342. "where " +
  343. "accntnumber like '"+like.trim()+"%' " +
  344. "order by accntcode ";
  345. }else if (jcbsearchBy.getSelectedIndex() == 3){
  346. likeQuery = "select " +
  347. "accntcode, bankcode, accntnumber, accntdesc " +
  348. "from accntmasterfile " +
  349. "where " +
  350. "accntdesc like '"+like.trim()+"%' " +
  351. "order by accntcode ";
  352. }
  353.  
  354.  
  355. int n = 0;
  356. Statement stmt = DBConnect.getConnection().createStatement();
  357. ResultSet rs = stmt.executeQuery(likeQuery);
  358. actionCursor.startWaitCursor(jContentPane);
  359. if (ok == false){
  360. while(jTable.getRowCount() != 0){
  361. tableSearch.removeRow(0);
  362. }
  363. ok = true;
  364. }
  365. while (rs.next()){
  366. tableSearch.addRow(new Object[]{rs.getRow(),rs.getString(1), rs.getString(2),rs.getString(3),rs.getString(4)});
  367. n++;
  368. }
  369. if (n > 0){
  370. jTable.setRowSelectionInterval(0, 0);
  371. jTable.grabFocus();
  372. }
  373. rs.close();
  374. stmt.close();
  375. }
  376. catch(Exception e){
  377. e.printStackTrace();
  378. }
  379. actionCursor.stopWaitCursor(jContentPane);
  380. }
  381.  
  382. private void setTable(){
  383. try {
  384. Statement stmt = DBConnect.getConnection().createStatement();
  385. ResultSet rs = stmt.executeQuery(defaultQuery);
  386. int n = 0;
  387. while (rs.next()){
  388. tempTable.addRow(new Object[]{rs.getRow(), rs.getString(1), rs.getString(2),rs.getString(3),rs.getString(4)});
  389. tableSearch.addRow(new Object[]{rs.getRow(), rs.getString(1), rs.getString(2),rs.getString(3),rs.getString(4)});
  390. n++;
  391. }
  392. rs.close();
  393. stmt.close();
  394. if (n > 0){
  395. jTable.setRowSelectionInterval(0, 0);
  396. jTable.grabFocus();
  397. }
  398. }
  399. catch(Exception e){
  400. e.printStackTrace();
  401. }
  402. }
  403.  
  404. private void setenabledUpdate(){
  405. accntMasterfile.jtBcode.grabFocus();
  406. accntMasterfile.jbtnadd.setText("Update");
  407. accntMasterfile.jbtnadd.setMnemonic('U');
  408. accntMasterfile.jbtnedit.setText("Delete");
  409. accntMasterfile.jbtnedit.setMnemonic('D');
  410. accntMasterfile.jbtnExit.setText("Cancel");
  411. accntMasterfile.jbtnExit.setMnemonic('C');
  412. accntMasterfile.jtAcode.setEnabled(false);
  413. accntMasterfile.jtBcode.setEnabled(true);
  414. accntMasterfile.jtAccntNo.setEnabled(true);
  415. accntMasterfile.jtAccontDesc.setEnabled(true);
  416. }
  417.  
  418. private void Cancel(){
  419. accntMasterfile.jtAcode.setText("");
  420. accntMasterfile.jtBcode.setText("");
  421. accntMasterfile.jtAccntNo.setText("");
  422. accntMasterfile.jtAccontDesc.setText("");
  423. accntMasterfile.jtAcode.setEnabled(false);
  424. accntMasterfile.jtBcode.setEnabled(false);
  425. accntMasterfile.jtAccntNo.setEnabled(false);
  426. accntMasterfile.jtAccontDesc.setEnabled(false);
  427. }
  428. }
Last edited by Ancient Dragon; Jul 21st, 2009 at 1:51 am. Reason: corrected code tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: search engine in java

 
0
  #4
Jul 17th, 2009
oliver, just stop posting.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 19
Reputation: oliver_lundag has a little shameless behaviour in the past 
Solved Threads: 0
oliver_lundag oliver_lundag is offline Offline
Newbie Poster

Re: search engine in java

 
0
  #5
Jul 17th, 2009
why?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: search engine in java

 
0
  #6
Jul 17th, 2009
Originally Posted by oliver_lundag View Post
why?
  1. Don't talk with old or solved threads.
  2. Use BB code tags
  3. Read all posts of a thread and then put your comment.
Last edited by adatapost; Jul 17th, 2009 at 2:23 am.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: search engine in java

 
1
  #7
Jul 17th, 2009
4. stop hi-jacking threads
5. don't post complete code (at least initially)
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 19
Reputation: oliver_lundag has a little shameless behaviour in the past 
Solved Threads: 0
oliver_lundag oliver_lundag is offline Offline
Newbie Poster

Re: search engine in java

 
0
  #8
Jul 17th, 2009
I am the one who made that code. just want to share it. why are you complaining... I just want to share... instead of saying that thing to me why don't you try to help those people who needs help. I think you are selfish.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 8
Reputation: karamjeet2004 is an unknown quantity at this point 
Solved Threads: 0
karamjeet2004 karamjeet2004 is offline Offline
Newbie Poster

Re: search engine in java

 
0
  #9
Jul 20th, 2009
thanks for the code
i am new to java
it took me a week to understand
but anyway thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: search engine in java

 
0
  #10
Jul 20th, 2009
Thanks,
Mark this thread as "Solved" if you get appropriate solution.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC