How to create Graph/chart(Bar ,Pie , Line ) in Java First one should use JFreeChart library and install JFreeChart and include jar file in Project Builder(Add external Jar file).Call Function to display Graph/Chart based on Sql query that means Data fetched from Sql query synchronized with chart/graph. When user clicks on show chart button 3D bar chart appears. Following code executes ,it displays 3D bar chart for student's marks in particlaur Exam... Do not forget to import following files in your java code import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.labels.ItemLabelAnchor; import org.jfree.chart.labels.ItemLabelPosition; import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.data.jdbc.JDBCCategoryDataset; import org.jfree....
Posts
Showing posts from May, 2022
- Get link
- X
- Other Apps
To Display Dropdown List(JCombobox) Item in Non editable JTextField in Java Swing If user selects item in dropdown List and Display the selected item in another Non editable Text field...below mention code will be helpful in achieving this.. JComboBox gender = new JComboBox(); gender.setEditable(true); gender.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String s_Value = gender.getSelectedItem().toString(); dispgender.setText(s_Value); }}); Here gender is JCombobox item has 2 values ie. Male, Female dispgender is non editable JTextfield in which selected item will be displayed. Run the code and enjoy....
- Get link
- X
- Other Apps
To show/Display Data in Table Format in Java To Display Records of particular Table in Database into JTable one needs to import JAR file rs2xml.jar in Build path in desired project(right click on project and select Build path configuration) and following statement in Declaration part in JAVA code, Below is the code when user click on Load Data button... import net.proteanit.sql.DbUtils; JButton btnNewButton = new JButton("Load Data"); btnNewButton.setFont(new Font("Verdana", Font.PLAIN, 12)); btnNewButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { Connection conn = getConnection(); String query="select cast(staff_code as unsigned)Id,F_name Name,case sex when 'M' Then 'Male' when 'F' then 'Female' end Gender from sch_db.staff_master order by id"; PreparedStatement stat = conn.prepareStatement(query); ResultSet res=stat.executeQuery(); ...
- Get link
- X
- Other Apps
Deletion of Database records from Java Frontend(JFrame) First establish Database connection from Frontend .... Here one can see Connection conn statement that I define in previous post simply copy from it nad paste it...rest is delete function(delrec)..modify code to suit your needs... public void delrec() throws Exception{ try { Connection conn=getConnection(); PreparedStatement delrec= conn.prepareStatement("Delete from sch_db.student where st_id = ? "); delrec.setString(1,Adm_No.getText()); delrec.executeUpdate(); } catch(Exception ez){System.out.println(ez);} finally { JOptionPane.showMessageDialog(null, "Record Deleted","Delete Confirmation",JOptionPane.DEFAULT_OPTION); //System.out.println("Record Deleted"); }} When user Press Delete button after displaying desired record ... JButton btnNewButton_2 = new JButton("Delete"); btnNewButton_2.addActio...
- Get link
- X
- Other Apps
Query & Update/Edit user entered Data in Java & My Sql First retrieve Data(Query) from MqSql Database and make desired changes in it and update it to Database. When user click on update button following code executes.. JButton btnNewButton_1 = new JButton("Update"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); btnNewButton_1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { updaterec(); } catch(Exception ex){System.out.println(e);} finally { System.out.println("Updation Complete"); } } }); //////////////////////////// public void updaterec() throws Exception{ PreparedStatement ps = null; try { Connection conn=getConnection(); String query= "update sch_db.student set st_class=?,st_section=?,stream=?,bus_stop = ?,stoppage=?,st_address=?,st_city=?,where substr(st_id,1,4) = ?...
- Get link
- X
- Other Apps
Insert/Add Data from Java(JFrame Frontend) into My Sql(Backend-Database) First to make sure that Database Connection is in place and proper My sql Driver is in place by adding JAR file in Build path option in Java eclipse. Following is the code for successful database connection. public static Connection getConnection() throws Exception{ try { String driver="com.mysql.cj.jdbc.Driver"; String url="jdbc:mysql://127.0.0.1:3306/sch_db"; String username="root"; String password="Pintoo@1404"; Class.forName(driver); Connection conn=(Connection) DriverManager.getConnection(url,username,password); System.out.println("Connected"); return conn; } catch(Exception e) {System.out.println(e);} return null; } Insert/add data entered by user: public static void postrec() throws Exception{ try { Connection conn=getConnection(); PreparedStatement posted= conn.prepareStatement("INSERT INTO sch_db.STUD...