You are on page 1of 10

Login cu user si parola

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
String password;
String user;
user = username.getText();
password = pass.getText();
if(password.equals("student") && user.equals("Parola@RD!@") )
{
new meniu().setVisible(true);
this.dispose();
}
else{
mesaj.setText("Please try again.");
}
}
Creare structura tabele

private void tabeStudentActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
Connection con;
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");
con =
DriverManager.getConnection("jdbc:derby://localhost:1527/Test_curs_2020;create=true;user=stude
nt;password=Parola@RD!@");
Statement stmt = con.createStatement();
stmt.executeUpdate("CREATE TABLE student" +
"(Nr_matricol INTEGER ," +"Nume_stud VARCHAR(50),"+
"AN VARCHAR(4)," +
"Grupa VARCHAR(4),"+"Telefon VARCHAR(11))");
}
catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(rootPane, e.toString(),"Mesaj Error...",
JOptionPane.INFORMATION_MESSAGE);
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(rootPane, e.toString(),"Mesaj Error...",
JOptionPane.INFORMATION_MESSAGE);
}
}
private void tabelCrediteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Connection con;
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");
con =
DriverManager.getConnection("jdbc:derby://localhost:1527/Test_curs_2020;create=true;user=stude
nt;password=Parola@RD!@");
Statement stmt = con.createStatement();
stmt.executeUpdate("CREATE TABLE credite" +
"(id_cred INTEGER ,"+"num_cred VARCHAR(50)," + "nr_cred VARCHAR(5),"+
"cod_cred VARCHAR(50))");
}
catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(rootPane, e.toString(),"Mesaj Error...",
JOptionPane.INFORMATION_MESSAGE);
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(rootPane, e.toString(),"Mesaj Error...",
JOptionPane.INFORMATION_MESSAGE);
}

}
Adaugare credite

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
Connection dB=null;
String s1= ID.getText();
String s2= Nume_Curs.getText();
String s3= Nr_Credit.getText();
String s4= Cod_credit.getText();
int int1=Integer.parseInt(s1);
String dbURL =
"jdbc:derby://localhost:1527/Test_curs_2020;create=true;user=student;password=Parola@RD!@";
String tableName = "credite";

Connection conn = null;


Statement stmt = null;
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
//Get a connection
conn = DriverManager.getConnection(dbURL);
}
catch (Exception except)
{
}
try
{ stmt = conn.createStatement();
stmt.execute("insert into " + tableName + " values (" +
int1 + ",'" + s2 + "','" + s3 +"','" + s4 +"')");
mesaj.setText(" Inregistrarea a fost adaugata cu succes");
stmt.close();
}
catch (SQLException sqlExcept)
{
}
ID.setText("");
Nume_Curs.setText("");
Nr_Credit.setText("");
Cod_credit.setText("");
// mesaj.setText("");

}
//actiune RESET
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ID.setText("");
Nume_Curs.setText("");
Nr_Credit.setText("");
Cod_credit.setText("");
mesaj.setText(" ");
}
UPDATE

private void deleteActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

Connection dB=null;

String s1= ID.getText();

String s2= Nume_Curs.getText();

String s3= Nr_Credit.getText();

String s4= cod_credit.getText();

int int1=Integer.parseInt(s1);

String url =
"jdbc:derby://localhost:1527/Test_curs_2020;create=true;user=student;password=Parola@RD!@";

String tableName = "credite";

// jdbc Connection

Connection conn = null;

Statement stmt = null;

try

Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
//Get a connection

conn = DriverManager.getConnection(url);

catch (Exception except)

{ except.printStackTrace(); }

try

{ stmt = conn.createStatement();

stmt.executeUpdate("UPDATE "+ tableName +" set num_cred='" +

s2+"'" + ",nr_cred='" + s3+"'" +",cod_cred='" + s4+"'" + " WHERE id_cred=" + int1);

mesaj.setText(" Inregistrarea a fost modificata cu succes");

stmt.close(); }

catch (SQLException sqlExcept)

{ sqlExcept.printStackTrace(); }

ID.setText("");

Nume_Curs.setText("");

Nr_Credit.setText("");

cod_credit.setText("");

//mesaj.setText("");

}
AFISARE

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
String url =
"jdbc:derby://localhost:1527/Test_curs_2020;create=true;user=student;password=Parola@RD!@";
String tableName = "credite";

Connection conn = null;


Statement stmt = null;

try
{
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
//Get a connection
conn = DriverManager.getConnection(url);
}
catch (Exception except)
{
except.printStackTrace();
}
try{
int int1=0;
String s1=new String();
s1=this.ID.getText();
int1=Integer.parseInt(s1);
conn = DriverManager.getConnection(url);

Statement stmt1 = conn.createStatement();


ResultSet rs=stmt1.executeQuery("SELECT * FROM " + tableName+" where id_cred="+int1);
while(rs.next())
{
Nume_Curs.setText(rs.getString("num_cred"));
Nr_Credit.setText(rs.getString("nr_cred"));
Cod_credit.setText(rs.getString("cod_cred"));
}
mesaj.setText(" Inregistrarea a fost afisata");

}
catch(SQLException e)
{
JOptionPane.showMessageDialog(rootPane, e.toString(),"Error 1111...",
JOptionPane.INFORMATION_MESSAGE);
}
}
STERGERE dupa ID curs

private void deleteActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
String url =
"jdbc:derby://localhost:1527/Test_curs_2020;create=true;user=student;password=Parola@RD!@";
String tableName = "credite";
// jdbc Connection
Connection conn = null;
Statement stmt = null;
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
conn = DriverManager.getConnection(url);
}
catch (Exception except)
{
except.printStackTrace();
}
try{
int int1=0;
String s1=new String();
s1=this.ID.getText();
int1=Integer.parseInt(s1);
conn = DriverManager.getConnection(url);
Statement stmt1 = conn.createStatement();
stmt1.executeUpdate("DELETE FROM "+tableName+" where id_cred="+int1);
System.out.println("aa");

mesaj.setText(" Stergerea a fost efectuata!");


}
catch(SQLException e)
{
JOptionPane.showMessageDialog(rootPane, e.toString(),"Error 1111...",
JOptionPane.INFORMATION_MESSAGE);
}
ID.setText("");
Nume_Curs.setText("");
Nr_Credit.setText("");
Cod_credit.setText("");
// mesaj.setText("");
}

You might also like