1

I am trying to build a library management desktop app by netbeans.

I succeeded in connecting database and adding new book and member information in database table.

Now I have tried to search information by id in table that is unique and want to show related information somewhere, such as in a Label or in a Text Field but I don't know the coding for that.

I have learned simple core java and before it a use discretionary and list to Store my infomation but in database connection how can I use if else clause ex.:

if(list-name.contains (book id))
{
     system.out.println("the book id already registered.");
}
else
{
      system.out.println("tthis book id is available.");
}

How can I write such as expression for database tables?

6
  • Please provide a final question matching with your needs, such as "how to display it on a screen ? " or "how to get data from database?" Commented May 30, 2016 at 12:04
  • Thankz for ur time really. Going try this Commented Jun 5, 2016 at 5:29
  • It's working. Thank uh so much again . Another question in my mind is that I want a jtanlbe that show all data from database table. I've tried this by using jtable biding prosperity <biding source<import data from<mydatatablename. But it gives an error shows biding expreasion can't be null. Plese help Commented Jun 5, 2016 at 6:35
  • maybe it is a good idea to post another question on Stack Overflow. If the answer below helped you, please mark it as accepted. :) Commented Jun 5, 2016 at 20:36
  • How?? Can't find how to mark it as accepted Commented Jun 6, 2016 at 3:25

1 Answer 1

1

you should try to read jdbc connection, and then take this demo example to raed out it helpful for you

    try{
    Connection con1;
    Class.forName("com.mysql.jdbc.Driver");
    con1=(Connection)DriverManager.getConnection("jdbc:mysql://192.168.101.1:3306/dbname","username","password");
    PreparedStatement ps1=(PreparedStatement)con1.prepareStatement("SELECT * from tablename where columnname=valueofid");
    String str;
    ResultSet rs1=ps1.executeQuery();

    while(rs1.next()){
        int id=rs1.getInt("ID");
        String bookname=rs1.getString("clnmae1");
    String bookauthor=rs1.getString("clname2");

    //// there you can use label settext() method where to show your data
        }
       con1.close();

    } catch(Exception ex){
        out.print(ex);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.