Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

home / study / engineering / computer science / computer science questions and a

ID: 3859430 • Letter: H

Question

home / study / engineering / computer science / computer science questions and answers / c programming language: file i/o write a mini-database ...

Question: C Programming Language: FILE I/O write a mini-data...

C Programming Language: FILE I/O

write a mini-database that uses basic file I/O. You may choose any file format you like, including flat file, XML, JSON, comma separated values, binary files, or a format of your own choosing, but it must support the following:

Some SQL-like operations, namely:

SELECT * FROM TableName WHERE Field1="value"

DELETE FROM TableName WHERE Field1="value"

UPDATE TableName SET Field1="new value" WHERE Field2="value"


Creation and deletion of multiple tables per database:

CREATE TABLE TableName FIELDS [Field1, Field2, ...]

DROP TABLE TableName

In addition, the program must be able to select a database, creating one if it does not exist, via a command-line parameter.


Thanks in advance

Explanation / Answer

hI,

Please ahve a look on the below program for JDBC connection to store the data from the program and vice versa

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBC_Connection_Demo
{
/* static block is executed when a class is loaded into memory
* this block loads MySQL's JDBC driver
*/
static
{
try
{
// loads com.mysql.jdbc.Driver into memory
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException cnf)
{
System.out.println("Driver could not be loaded: " + cnf);
}
}

public static void main(String[] args)
{
String connectionUrl = "jdbc:MYSQL CONNECTION PASS HERE";
String dbUser = "root";
String dbPwd = "mysql";
Connection conn;
ResultSet rs;
String queryString = "SELECT ID, NAME FROM EXPTABLE";

try
{
conn = DriverManager.getConnection(connectionUrl, dbUser, dbPwd);
Statement stmt = conn.createStatement();

// INSERT A RECORD
stmt.executeUpdate("INSERT INTO EXPTABLE (NAME) VALUES ("TINU K")");

// SELECT ALL RECORDS FROM EXPTABLE
rs = stmt.executeQuery(queryString);

System.out.println("ID NAME");
System.out.println("============");
while(rs.next())
{
System.out.print(rs.getInt("id") + ". " + rs.getString("name"));
System.out.println();
}
if (conn != null)
{
conn.close();
conn = null;
}
}
catch (SQLException sqle)
{
System.out.println("SQL Exception thrown: " + sqle);
}
}