Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package agenda;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Agenda {
- public static void main(String[] args) {
- System.out.print("wtf");
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection c =
- DriverManager.getConnection("jdbc:mysql://localhost:3306/databaseagenda", "root", "");
- Statement st = c.createStatement();
- if(args.length >0){
- if(args[0].equals("-v")){
- if(args.length==2){
- //apro file e lo leggo
- ResultSet s= st.executeQuery("SELECT * "
- + "FROM agenda "
- + "WHERE giorno = '"+args[1]+ "' ");//metto più per fargli capire che devo trovare il valore dentro args
- while(s.next()){
- System.out.print(s.getString(1)+ " "+ s.getString(2)+ " "+ s.getString(3));
- }
- } else{
- System.out.print("errore passaggio parametri");
- System.exit(-1);
- }
- } else if(args.equals("-s")){
- if(args.length==2){
- try {
- FileReader f= new FileReader("Agenda.txt");
- BufferedReader b= new BufferedReader(f);
- String line="";
- while((line = b.readLine())!=null){
- String [] splitted = line.split(" ");
- if(args[1].equals(splitted[2])){
- System.out.println(line);
- }
- }
- b.close();
- f.close();
- //if args[1] è contenuto nel file{
- // allora restituisci il contenuto di quel giorno}
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else{
- System.out.print("errore passaggio parametri");
- System.exit(-1);
- }
- }
- }
- else if(args.equals("-i")){
- if(args.length==4){
- ResultSet s= st.executeQuery("SELECT * "
- + "FROM agenda "
- + "WHERE giorno = '"+args[1]+"' AND ora = '"+args[2]+"'");
- s.getString(1);
- if(s.wasNull()){
- st.execute("INSERT INTO agenda(ora,giorno,descrizione) "
- + "VALUES ('"+args[2]+"','"+args[1]+"','"+args[3]+"')");
- }else{
- System.out.println("riga già inserita");
- }
- }else{
- System.out.print("errore passaggio parametri");
- System.exit(-1);
- }
- }
- } catch (InstantiationException e) {
- System.out.print("wtf");
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- System.out.print("wtf");
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- System.out.print("classe non trovata");
- e.printStackTrace();
- } catch (SQLException e) {
- System.out.print("wtf");
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement