Click here to Skip to main content
Click here to Skip to main content

Message Manager

, 8 Feb 2012
Rate this:
Please Sign up or sign in to vote.
Sending and receiving message, user authentication, user permission, priority message

Introduction

As you know, the amount of source code for Java (Netbeans) on the Internet is much less than other languages??. So I sent this article. This article may be helpful for people who work with Netbeans, Java(J2SE), Mysql. In this article, you will learn: Sending and receiving message, user authentication, user permission, priority message.

Training Tips Article

  1. Working with the Mysql commands from Java (Netbeans)
  2. Message box in Java (Netbeans)
  3. Working with the Java Jtable
  4. How to connect to database from Netbeans (connection string, Mysql authentication)
  5. Working with the Java Jpanel
  6. How ResultSet(RS) works
  7. User management
  8. Giving access to users (user permission)
  9. Priority for letters

In the first, manager with username: admin and password: 313 is entered and the user defines and gives to each user the appropriate permissions.

Using the Code

The database connection and functions are in Database.java. The following functions and variables are used in this class.

Connection String: A connection string contains initialization information that is passed as a parameter from a data provider to a data source. The syntax depends on the data provider, and the connection string is parsed during the attempt to open a connection. Here we call that connectionUrl.

//connection string //"Archive" is database name

private static String connectionUrl = 
    "jdbc:mysql://localhost:3306/archive user=root & password=123"; 

Retrieve Data function: The function to retrieve records from database and fill those in result set, this function has an input.

public static void retrieveData(String SQL) throws Exception {
    rs = stmt.executeQuery(SQL);
    while (rs.next()) {
        System.out.println(rs.getString("ProductName") + " : " + 
    rs.getString("QuantityPerUnit") + " : " +
        rs.getString("UnitPrice") + " : " + 
    rs.getString("UnitsInStock") + " : " +
        rs.getString("UnitsOnOrder") + " : " + 
    rs.getString("ReOrderLevel") + " : " + rs.getString("Discontinued"));
    }
}

Command function: The function for send commands to the database (insert, update, delete).

public static void Command(String SQL) throws Exception {
    try  {
        Class.forName("com.mysql.jdbc.Driver");
        con=  DriverManager.getConnection(connectionUrl);
        stmt = con.createStatement();
        stmt.executeUpdate(SQL);
            System.out.print("?? ?????? ????? ??.");
        }catch(Exception insError){
            System.out.print(insError);            }
}

Select function: This function is used for selecting record(s) with any condition from database and filling those in result set.

public ResultSet select(String SQL)  {
    try  {
    Class.forName("com.mysql.jdbc.Driver");
    con=  DriverManager.getConnection(connectionUrl);
    stmt = con.createStatement();
     ResultSet s=stmt.executeQuery(SQL);
        return s;
    }catch(Exception insError){
        System.out.print(insError);
    }
    return null;
}

Points of Interest

Netbeans is not just for mobile programming. We can develop in this IDE web, Java desktop, Enterprise, PHP, C/C++, etc. application.

History

  • 7th February, 2012: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

ebrahim amini sharifi
Software Developer (Senior) aisoft-rayvarz
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I'm a senior java/j2ee developer. I'm just start be a part-time freelancer. I have years of experience in web application development. I'm good at JSF,Servlet,Applet and also j2ee technologies like JSP/Servlet, Hibernate.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 8 Feb 2012
Article Copyright 2012 by ebrahim amini sharifi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid