Write a java program which takes any of the following commands as command line a
ID: 3921371 • Letter: W
Question
Write a java program which takes any of the following commands as command line argument (not as input), and executes them using JDBC: insert into relation name value1 value2 value3. Inserts a tuple into the specified relation with the specified values; make sure you use a prepared statement; test it with input containing single quotes (if you run from command line, enclose those in double quotes so Linux doesn't interpret the quotes) you can assume that all values are strings for simplicity select from relation name Prints all tuples from the specified relation. For the purpose of this assignment, you should assume that relation name is one of "instructor", "student" or "takes", and not use database metadata features to print the tuples. select from relation name where "condition Executes a query with the specified condition. Note the use of double quotes so that the condition comes as a single command line parameter. Again assume relation name is one of those from the previous feature. So this is really a small addition to the code for the previous feature, do NOT make a separate copy of the code. select from relationname1 relation name Displays result of natural join of the two relations. This time, use the result set metadata feature to display all values from the query result; don't worry about displaying column names, that is optional, we only care about values being displayed.Explanation / Answer
package inventoryread;
import java.sql.*;
import java.sql.PreparedStatement;
import java.util.Scanner;
import java.sql.Connection;
public class Validation {
private PreparedStatement statement;
private Connection con;
private String x, y;
public Validation(){
String stmt,qry,typeqry;
Scanner sc=new Scanner();
System.out.println("enter insert to insert values");
typeqry=sc.next();
if(typeqry=="insert"){
System.out.println("query");
qry=sc.next();
private void setString(String qry, String stmt) {
// TODO Auto-generated method stub
}
}
}
public Validation(String userID) {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "");
statement = con.prepareStatement(
stmt);
ResultSet rs = statement.executeQuery();
while (rs.next()) {
x = rs.getString(1);
System.out.print(x);
System.out.print(" ");
y = rs.getString(2);
System.out.println(y);
}
} catch (Exception ex) {
System.out.println(ex);
}
}
public static void main(String args[])
{
validation v=new validation();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.