Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,158,232 members, 7,836,114 topics. Date: Tuesday, 21 May 2024 at 08:58 PM

How Can I Search A Record In SQL Database? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Can I Search A Record In SQL Database? (1887 Views)

Sql Database Error Gurus Pls Come In / Help!!! Login Failed For User in SQL Server / SQL Database Repair (2) (3) (4)

(1) (Reply) (Go Down)

How Can I Search A Record In SQL Database? by epospiky(m): 12:37pm On Jan 08, 2016
Hi. I am currently learning how to create database in java using SQL. I have successfully implemented commands like add new record, delete new record, update new record, next record, previous record, first record and last record. I am now looking forward to creating a search command in the database but i'm lost on how to go about it. The code is actually my concern. Please anyone with an idea should help me out.
Re: How Can I Search A Record In SQL Database? by Nobody: 1:01pm On Jan 08, 2016
www.java2s.com/Code/Java/Database-SQL-JDBC/JDBCselect.htm

For example if your are asked to find the male or female students use a query to search like

SELECT Male, female FROM Students

don't forget to know the format of your db and remember to use import SQL .

www.tutorialspoint.com/jdbc/jdbc-select-records.htm
Re: How Can I Search A Record In SQL Database? by Nobody: 1:35pm On Jan 08, 2016
Try searching for clues
Re: How Can I Search A Record In SQL Database? by epospiky(m): 9:12am On Jan 09, 2016
proxy20:
www.java2s.com/Code/Java/Database-SQL-JDBC/JDBCselect.htm

For example if your are asked to find the male or female students use a query to search like

SELECT Male, female FROM Students

don't forget to know the format of your db and remember to use import SQL .

www.tutorialspoint.com/jdbc/jdbc-select-records.htm

Thanks. From my understanding of what you posted, it seems i am to create a class with the "select" method and the output of the operation is going to be more than one record. I would rather it's just a single output with a particular key query. How about that?
Re: How Can I Search A Record In SQL Database? by Nobody: 9:20am On Jan 09, 2016
Exactly you need create a class for the method

SELECT * FROM Male



SELECT * FROM ID1.Name

SELECT * FROM Faith WHERE
AGE =19


will select one output from you database .
The ID number or SN is very important in database management .

I think you need to connect your database through local host since you can't put it in in the package explorer by creating a directory and import the db . I don't know if that is possible .


put the zip file of your codes for me to download here on nairaland
Re: How Can I Search A Record In SQL Database? by epospiky(m): 6:29pm On Jan 09, 2016
ok i'll do just that. Just give me a moment.
Re: How Can I Search A Record In SQL Database? by epospiky(m): 6:46pm On Jan 09, 2016
proxy20:
Exactly you need create a class for the method

SELECT * FROM Male



SELECT * FROM ID1.Name

SELECT * FROM Faith WHERE
AGE =19


will select one output from you database .
The ID number or SN is very important in database management .

I think you need to connect your database through local host since you can't put it in in the package explorer by creating a directory and import the db . I don't know if that is possible .


put the zip file of your codes for me to download here on nairaland

Here it is.

Re: How Can I Search A Record In SQL Database? by Nobody: 6:50pm On Jan 09, 2016
Thanks bro
Re: How Can I Search A Record In SQL Database? by laykhorn(m): 9:07pm On Jan 09, 2016
epospiky:
Hi. I am currently learning how to create database in java using SQL. I have successfully implemented commands like add new record, delete new record, update new record, next record, previous record, first record and last record. I am now looking forward to creating a search command in the database but i'm lost on how to go about it. The code is actually my concern. Please anyone with an idea should help me out.

First, in the structure of your database while creating it, make an [b] id e.g. in the case of Facebook or username in the case of NL and most sites, you must have a parameter that has an index of PRIMARY which means the value of this input can only be taken on one table row and no other i.e. only one person can use such username or id.

You can query such column after selecting database and connecting to it with select queries like the below

"SELECT * FROM users WHERE id = ?", id

" SELECT * FROM users WHERE username = ?", username


NB: users was used as name of db
id and usernames after comma is how you'll retrieve your cars from db e.g. $_POST or $_REQUEST in PHP[/b]

Re: How Can I Search A Record In SQL Database? by Nobody: 10:25pm On Jan 09, 2016
I made some adjustments . I think you have to create a separate class like select.java .

Re: How Can I Search A Record In SQL Database? by epospiky(m): 10:26pm On Jan 09, 2016
laykhorn:


First, in the structure of your database while creating it, make an [b] id e.g. in the case of Facebook or username in the case of NL and most sites, you must have a parameter that has an index of PRIMARY which means the value of this input can only be taken on one table row and no other i.e. only one person can use such username or id.

You can query such column after selecting database and connecting to it with select queries like the below

"SELECT * FROM users WHERE id = ?", id

" SELECT * FROM users WHERE username = ?", username


NB: users was used as name of db
id and usernames after comma is how you'll retrieve your cars from db e.g. $_POST or $_REQUEST in PHP[/b]

I used the code in a button but it didn't work for me. It didn't even output anything. When i click on the search button it does nothing as if i never declared it.
Re: How Can I Search A Record In SQL Database? by epospiky(m): 10:30pm On Jan 09, 2016
proxy20:
I made some adjustments . I think you have to create a separate class like select.java .
Ok...waiting to see how it goes. Thanks dude.

1 Like

Re: How Can I Search A Record In SQL Database? by Nobody: 10:34pm On Jan 09, 2016
Alright
Re: How Can I Search A Record In SQL Database? by laykhorn(m): 11:17pm On Jan 09, 2016
epospiky:


I used the code in a button but it didn't work for me. It didn't even output anything. When i click on the search button it does nothing as if i never declared it.

Can I have a look at your code? You might have a bug somewhere.



Paste on pastebin.co,m its better there.
Re: How Can I Search A Record In SQL Database? by epospiky(m): 10:55am On Jan 10, 2016
laykhorn:


Can I have a look at your code? You might have a bug somewhere.



Paste on pastebin.co,m its better there.

it's done. take a look at it [url="pastebin.com/rNrBD64K"]here[/url]
Re: How Can I Search A Record In SQL Database? by laykhorn(m): 3:29pm On Jan 10, 2016
epospiky:


it's done. take a look at it [url="pastebin.com/rNrBD64K"]here[/url]

busy right now. I'll do in a few hours... If I dont by 6 today, remind me. My Laptop and Tab arent available here
Re: How Can I Search A Record In SQL Database? by epospiky(m): 9:30pm On Jan 10, 2016
laykhorn:


busy right now. I'll do in a few hours... If I dont by 6 today, remind me. My Laptop and Tab arent available here

Just want to remind you...kind of.

1 Like

Re: How Can I Search A Record In SQL Database? by laykhorn(m): 1:48pm On Jan 11, 2016
epospiky:


Just want to remind you...kind of.

Just Checked. Sorry, I don't do Java that much. JDBC isn't it for me
Re: How Can I Search A Record In SQL Database? by epospiky(m): 11:59pm On Jan 11, 2016
laykhorn:


Just Checked. Sorry, I don't do Java that much. JDBC isn't it for me
owkay. No qualms

1 Like

(1) (Reply)

Let's Create An E-learning Site/App Together!!! / More Than 750,000 Lenovo Laptops Have Spy Ware Pre-installed In Them / I Need A Php Teacher

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.