Question

Access Gallery Database Using a High-Level Language Acceptable Languages: C or any version (C++,C#, etc.) PHP...

Access Gallery Database Using a High-Level Language Acceptable Languages: C or any version (C++,C#, etc.) PHP XML Java Python Write an application that allows a user to: Print records from the DB Access any record based on attribute values Sort a report Program may use either dynamic or static sql, but static is preferred. Submit your program source and object code and a printout of it in

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please read given instructions in code carefully

package com.example.poc;

import java.sql.*;

public class SampleDb {

public SampleDb() {

// TODO Auto-generated constructor stub

}

// Assuming you have mysql installed on your system

// Create database name it gallery

// Create table gallery_table having attributes id and value both are integer

// (change as per your convenience make code change also);

public static void main(String args[]) {

try (Connection connection = createConnection();) {

SampleDb sampleDb = new SampleDb();

sampleDb.diplayAllRecords(connection);

// change input id value as per your requirement

Integer id = 2;

sampleDb.displaySpecificRecord(connection, id);

} catch (Exception e) {

System.out.println(e);

}

}

private void displaySpecificRecord(Connection connection, Integer id) throws SQLException {

Statement stmt = connection.createStatement();

// gallery table is sql tablename

ResultSet rs = stmt.executeQuery("select * from gallery_table where id=" + id + ";");

if (rs.isBeforeFirst()) {

while (rs.next()) {

System.out.println(rs.getInt("id") + " " + rs.getInt("value"));

}

} else {

System.out.println("Record not found for provide attribute");

}

}

private void diplayAllRecords(Connection connection) throws SQLException {

Statement stmt = connection.createStatement();

// gallery table is sql tablename

ResultSet rs = stmt.executeQuery("select * from gallery_table;");

if (rs.isBeforeFirst()) {

while (rs.next()) {

System.out.println(rs.getInt("id") + " " + rs.getInt("value"));

}

} else {

System.out.println("Nothing to print");

}

}

private static Connection createConnection() {

// Running on java 8

// for class not found exception put mysql-connector-java-5.0.8-bin.jar as

// external library

try {

Class.forName("com.mysql.jdbc.Driver");

// TODO put your database name instead of gallery and user-name password

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/gallery", "root", "root");

return con;

} catch (ClassNotFoundException | SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

}

Add a comment
Know the answer?
Add Answer to:
Access Gallery Database Using a High-Level Language Acceptable Languages: C or any version (C++,C#, etc.) PHP...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Project Description In this project, you will design and implement a database for keeping track of...

    Project Description In this project, you will design and implement a database for keeping track of information for an online “SOCIAL NETWORK” system (e.g. a simplified version of Facebook!). You will first design an EER schema diagram for this database application. Then, you will map the EER schema into a relational database schema and implement it on ORACLE or MySQL or some other relational DBMS. Finally, you will load some data into your database (via user Interface) and create some...

  • Read this article. Then write a 250 word response on two of the programs you like...

    Read this article. Then write a 250 word response on two of the programs you like the most. Open source business intelligence software 1. BIRT BIRT is an open source BI program that CloudTweaks says is often viewed as the industry standard. BIRT boasts “over 12 million downloads and over 2.5 million developers across 157 countries.” Its users include heavyweights such as Cisco, S1, and IBM (which is also a BIRT sponsor). They also have maturity going for them, as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT