项目作者: dodobasu

项目描述 :
Java Swing MySQL CRUD with JTable
高级语言: Java
项目地址: git://github.com/dodobasu/java_swing_mysql_crud.git
创建时间: 2018-02-17T05:22:55Z
项目社区:https://github.com/dodobasu/java_swing_mysql_crud

开源协议:

下载


JAVA DESKTOP MYSQL CRUD

Create Java Swing Project to CREATE UPDATE DELETE EDIT AND JTABLE

Getting Started

Download and open in Netbean 8.xx IDE

Prerequisites

  1. //////////CREATE DATABASE AND TABLE ////////////
  2. CREATE DATABASE `wbeducar_java`;--
  3. CREATE TABLE IF NOT EXISTS `user` (
  4. `id` int(11) NOT NULL AUTO_INCREMENT,
  5. `username` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
  6. `password` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  7. `user_status` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  8. `entry` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  9. PRIMARY KEY (`id`),
  10. UNIQUE KEY `id` (`id`)
  11. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=12 ;
  12. INSERT INTO `user` (`id`, `username`, `password`, `user_status`, `entry`) VALUES
  13. (1, 'admin', 'admin', 'Active', '2018-02-14 22:22:29');
  14. ////////// IMPORT /////////////////////
  15. import java.sql.Connection;
  16. import java.sql.DriverManager;
  17. import java.sql.SQLException;
  18. //////Others in JFrame //////
  19. import java.sql.PreparedStatement;
  20. import java.sql.ResultSet;
  21. import java.sql.Statement;
  22. import java.util.ArrayList;
  23. import javax.swing.JOptionPane;
  24. import javax.swing.table.DefaultTableModel;
  25. import javax.swing.table.TableModel;
  26. /////////// Database Connection in DBConnection.Java/////////
  27. private Connection DBConnection;
  28. public Connection connect(){
  29. try{
  30. Class.forName("com.mysql.jdbc.Driver");
  31. System.out.println("Driver Success");
  32. }
  33. catch(ClassNotFoundException cnfe){
  34. System.out.println("Driver not found" + cnfe);
  35. }
  36. String url="jdbc:mysql://localhost:3306/wbeducar_java";
  37. try{
  38. DBConnection=DriverManager.getConnection(url,"root","YOUR PASSWORD");
  39. System.out.println("Database Connected");
  40. }
  41. catch(SQLException se){
  42. System.out.println("Database Not Found");
  43. }
  44. return DBConnection;
  45. }
  46. ////// CALL CONNECTION IN OTHER FORM////////////
  47. Connection conn=new DBConnection().connect();
  48. //////////////// CHECK SELECT QUERY ON BUTTON CLICK EVENT /////////////////
  49. String sql="Select * FROM user where username=? AND password=?";
  50. try{
  51. PreparedStatement ps=conn.prepareStatement(sql);
  52. ps.setString(1,txtUser.getText());
  53. ps.setString(2,txtPass.getText());
  54. ResultSet rs=ps.executeQuery();
  55. if(rs.next()){
  56. this.dispose();
  57. MainMenu mm = new MainMenu();
  58. mm.show();
  59. }
  60. else {
  61. JOptionPane.showMessageDialog(null,"User Credential invalid");
  62. }
  63. }
  64. catch(HeadlessException | SQLException e){
  65. JOptionPane.showMessageDialog(null,"User Credential invalid" + e);
  66. }
  67. /////////////////// EXIT FROM APPLICATION ///////////
  68. System.exit(0);

Installing

Clone git and open dist folder and run javaapp.jar in windows environment

Built With

Contributing & Issue

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • Prativas Basu

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Bartosz Firyn