import Carti.Carti;
import Imprumut_Carti.Imprumut_Carti;
import Membrii.Membrii;
import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
import java.sql.SQLException;
import java.text.DateFormat;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*/
public class Main {
/**
* @param args the command line arguments
* @throws java.sql.SQLException
* @throws java.lang.ClassNotFoundException
* @throws java.lang.IllegalAccessException
* @throws java.lang.InstantiationException
*/
public static void main(String[] args) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
int valid;
int validd;
int validdd;
//Pentru Carti
Carti carte = new Carti(0, " ", " ", " ", " ", 0);
carte.InsertCarti(1, "The Chronicles of Narnia",
"description", "C.S. Lewis", "HarperCollins", 19);
carte.InsertCarti(2, "The Lord of the Flies",
"description", "C.S. Lewis", "Faber&Faber", 19);
}
package Carti;
import java.sql.*;
/**
*
*/
public class Carti {
static Connection conn = null;
static void connect() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException
{
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection ("jdbc:mysql://localhost/test", "root", "");
}
static String getString(String stt) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException
{
connect();
Statement st = conn.createStatement();
st.executeQuery(stt);
ResultSet rs = st.getResultSet();
rs.next();
String rez = rs.getString(1);
close();
return rez;
}
//Attributes
char[] form45 = new char[45];
char[] form256 = new char[256];
public int Id;
public String titlu = new String(form45);
public String descriere = new String(form256);
public String autor = new String(form45);
public String editie = new String(form45);
public int anPublicare;
//Constructor
public Carti(int Id, String titlu, String descriere, String autor,
String editie, int anPublicare)
{
this.Id = Id;
this.titlu = titlu;
this.descriere = descriere;
this.autor = autor;
this.editie = editie;
this.anPublicare=anPublicare;
}
//Overrride
@Override public String toString()
{
return "Id-ul cartii este: " + this.Id +
" Titlul sau este: "+this.titlu +
" Descrierea sa: " + this.descriere +
" Autorul: " + this.autor +
" Editia: " + this.editie +
" Anul Publicarii: " + this.anPublicare;
}
//Insert Carti
public void InsertCarti(int IdCartiVar, String titluVar, String DescriereVar,
String AutorVar, String EditieVar, int anPublicareVar) throws SQLException
{
PreparedStatement st = conn.prepareStatement("insert into Carti (Id,titlu"
+ ", descriere, autor, editie, anPublicare) values (?,?,?,?,?,?)");
st.setInt(1, IdCartiVar);
st.setString(2, titluVar);
st.setString(3, DescriereVar);
st.setString(4, AutorVar);
st.setString(5, EditieVar);
st.setInt(6, anPublicareVar);
st.execute();
}
static void close() throws SQLException
{
conn.close();
}
}