CS619 Test Phase – JAVA Login System with Netbeans and MS SQL Server Spring 2020 #CS619 #TestPhase #JAVA. For CS619 Test Phase, login system and user management system assigned to the students of Final year project which are to be made using Java PHP Android ASP and python.
In this video I will demonstrate login system form designing in NetBeans and JAVA application and then will lead to you how to connect with there Microsoft SQL server database with NetBeans and perform query based operation.
Topics of video
- 1. CS619 Test Phase Spring 2020
- 2. Java and MS Sql Server Test Phase
- 3. Netbeans and SQL Server login system
- 4. How to add controls in Netbeans in JAVA Form
- 5. How to make GUI forms in JAVA Test Phase
Task Develop an application for Library Management system in Java or PHP language using MySQL server or MS SQL server. You have to design and develop login screen and Admin Functions screen. Login screen will be connected with Database and username, password filed will be verified from Database upon clicking Login button.
If Username and Password do not match the records in the database then it will throw an error message “Invalid User and Password. Try Again” For your convenience sample Screen shots are given below. So, once a user logs in, he or she will be redirected to the admin menu as below. You have to draw the same Admin Function screen and no functionality required against each button in Admin Functions screen.
You should only add a message box against click event of each button showing this statement “Welcome to Library Management System and this is __________ Class Function” ____________ should be filled with either “Users” or “Books” word depending upon which class function it was called.
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
/*
* 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.
*/
/**
*
* @author Khayoo
*/
public class MyConnection {
// create a function to connect with mysql database
public static Connection getConnection(){
Connection con = null;
try {
//Class.forName("com.mysql.jdbc.Driver");
//con = DriverManager.getConnection("jdbc:mysql://localhost/java_login_register", "root", "");
String url = "jdbc:sqlserver://localhost;databaseName=userMgt;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(url);
JOptionPane.showMessageDialog(null, "Connected");
} catch (Exception ex) {
//System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(null, "not connected");
}
return con;
}
}
CS619 Test Phase – JAVA Login System with Netbeans and MS SQL Server Spring 2020
Login Form JAVA Code with SQL and Netbeans
import javax.swing.JOptionPane;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* 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.
*/
/**
*
* @author Khayoo
*/
public class NewJFrame extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Login");
jLabel1.setText("Username");
jLabel2.setText("Password ");
jButton1.setText("Login");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(104, 104, 104)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField1)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(47, 47, 47)))
.addContainerGap(102, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(47, 47, 47)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(21, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// MyConnection mycon=new MyConnection();
//mycon.getConnection();
// JOptionPane.showMessageDialog(null, "Welcome... to GUI");
PreparedStatement ps;
ResultSet rs;
String username=jTextField1.getText();
String password=jTextField2.getText();
if (username.length()==0 || password.length()==0)
JOptionPane.showMessageDialog(null, "Username and password must be enterned");
else
{
String query = "SELECT COUNT(*) FROM the_app_users WHERE username='"+username+"' AND password='"+password+"'";
//executing query
try {
ps = MyConnection.getConnection().prepareStatement(query);
//ps.setString(1, username);
//rs = ps.executeQuery();
rs = ps.executeQuery();
rs.next();
int count = rs.getInt(1);
rs.close();
if(count<=0)
JOptionPane.showMessageDialog(null, "Invalid User....");
else
{
JOptionPane.showMessageDialog(null, "Welcome... to Admin Dashboad");
this.setVisible(false);
new AdminDash().setVisible(true);
}
} catch (SQLException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration//GEN-END:variables
}