Академический Документы
Профессиональный Документы
Культура Документы
Раззакова
МЕТОДИЧЕСКИЕ УКАЗАНИЯ
Бишкек – 2020
Создание БД и подключение к NetBeans IDE 8.2
Тема: Информационная система детского сада
Оглавление
1. Создание нового проекта в SQL Server и построение архитектуры проекта...........................................3
6. Создание графика......................................................................................................................................48
1. Создание нового проекта в SQL Server и построение архитектуры
проекта.
1.1. Создание новой базы данных (далее БД)
Рис.1.
1.2. Задаем имя БД, в данном случаем у меня название shop_netbeans
Рис.2 –
1.3. Создаем семь таблиц как показано на рис.3
Рис.3
1.4. Заполняем каждую таблицу данными как указано в соответствующей
картинке
Рис.12 – представления
update employee
set FIO =@FIO, dateborn = @dateborn , position = @position, adress = @adress ,
tel_number = @tel_number ,
kruzhok = @kruzhid,groups= @grid
where id=@id
end
3. Удаление данных в сотрудниках
ALTER procedure [dbo].[delete_employee]
@id tinyint
as
delete from employee
where id= @id
4. Создание новых данных в таблице child
create procedure [dbo].[insert_child]
@FIO varchar(20),
@dateborn varchar(20),
@address varchar(20),
@tel_dad varchar(25),
@tel_mom varchar(25),
@groups varchar(20),
@kruzhok varchar(20),
@nationality varchar(20)
AS
begin
declare @grid tinyint ;
update [group]
set @grid = [group].id
where [group].groups= @groups
update children
set FIO =@FIO, dateborn = @dateborn , [address] = @address , tel_dad = @tel_dad
,tel_mom = @tel_mom,
groups= @grid , kruzhok = @kruzhid, nationality = @natid
where id=@id
end
7. Удаление в children
create procedure [dbo].[delete_child]
@id tinyint
as
delete from children
where id= @id
Рис.17
2.2. Задаем имя проекту, у меня «Shop»-> нажимаем на кнопку «Готово».
Рис.18
Поздраляю! Вы успешно создали проект.
3. Создание структуры проекта.
3.1. Необходимо нажать левой кнопкой мыши на раздел «Пакеты иходных
кодов»-> «Новый» -> «форма JFrame»
Рис.21
3.4. Необходимо открыть файл Shop.java и прописать ниже указанный код.
package shop;
// импортируем необходимые пакеты
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Zapadai
*/
import java.sql.*;
import javax.swing.*;
con=DriverManager.getConnection(connectionURL);
System.out.println("Соединение успешно !");
}
catch(SQLException e){
System.out.println(e);
}
return con;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ClassNotFoundException {
// TODO code application logic here
connect();
}
3.5. Необходимо создать новое окно JFrame, как создавали в пункте 2.1.
Дадим название loginFram-> в появивщемся окне необходимо создать
2 кнопки (Button), 2 Label , 1 – passwordField, 1 JTextField, как на рис.1
Рис.22
На кнопку «Войти» пропишем ниже указанный код
/**
*
* @author Zapadai
*/
public class loginFrame extends javax.swing.JFrame {
Connection conn = null;
ResultSet rs = null;
CallableStatement stored_pro = null;
/**
* Creates new form loginFrame
*/
public loginFrame() {
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">
private void initComponents() {
pack();
}// </editor-fold>
/**
* @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(loginFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(loginFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(loginFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(loginFrame.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 loginFrame().setVisible(true);
}
});
}
Что бы загрузить картинку, нужно создать JLabel -> очистить поле text -> в icon
добавить фотографию.
Полный листинг
package shop;
/**
*
* @author Zapadai
*/
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">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
pack();
}// </editor-fold>
/**
* @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>
}
pst.close();
}
catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
}
Вставим код для каждого поля со списком
*Чтобы в полях со списком отображались не айдишки, а сами данные
private void open_jComboBox1(){
try {
String sql= "Select *from position";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
String position = rs.getString("position");
jComboBox1.addItem(position);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
while(rs.next()){
String kruzhok = rs.getString("kruzhok");
jComboBox2.addItem(kruzhok);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
private void open_jComboBox3(){
try {
String sql= "Select *from [group]";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
String groups = rs.getString("groups");
jComboBox3.addItem(groups);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
Заполняем поле databaseName, задаем имя базы данных созданное в MSSQL SERVER -> далее
нажимаем на кнопку «Test»
Если после вышло сообщение как на рисунке ниже, поздравляю, вы успешно создали связь с БД
Далее нажимаем на «ОК» -> на кнопку «Save».
showMeAllReport();
try{
conn = Shop.connect();
JasperDesign jasperDesign = JRXmlLoader.load("C:\\Users\\Zapadai\\Documents\\
NetBeansProjects\\Shop\\src\\shop\\report1.jrxml");
String sql = "SELECT View_employee.\"id\" AS View_employee_id, View_employee.\"FIO\" AS
View_employee_FIO, View_employee.\"dateborn\" AS View_employee_dateborn,
View_employee.\"position\" AS View_employee_position, View_employee.\"adress\" AS
View_employee_adress, View_employee.\"tel_number\" AS View_employee_tel_number,
View_employee.\"kruzhok\" AS View_employee_kruzhok, View_employee.\"groups\" AS
View_employee_groups FROM \"dbo\".\"View_employee\" View_employee";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
}
catch(Exception e){
e.printStackTrace();
}
}
Идентично создаем еще один отчет, он понадобится для вывода отчета по
введенному айди
Вставим код для кнопки «отчет по№»
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
showById();
}
/**
* 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">
private void initComponents() {
jLabel4.setText("Адресс");
jLabel5.setText("Должность");
jTextField11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField11ActionPerformed(evt);
}
});
jLabel6.setText("Номер телефона");
jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jTable2MousePressed(evt);
}
});
jScrollPane2.setViewportView(jTable2);
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jLabel7.setText("Кружок");
jLabel1.setText("№");
jLabel8.setText("Группа");
jLabel2.setText("ФИО");
jTextField13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField13ActionPerformed(evt);
}
});
jButton5.setText("Добавить ");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("Обновить данные");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jButton7.setText("удалить запись");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jButton1.setText("отчет по №");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
pack();
}// </editor-fold>
try{
conn = Shop.connect();
JasperDesign jasperDesign = JRXmlLoader.load("C:\\Users\\Zapadai\\Documents\\
NetBeansProjects\\Shop\\src\\shop\\report1.jrxml");
String sql = "SELECT View_employee.\"id\" AS View_employee_id, View_employee.\"FIO\" AS
View_employee_FIO, View_employee.\"dateborn\" AS View_employee_dateborn,
View_employee.\"position\" AS View_employee_position, View_employee.\"adress\" AS
View_employee_adress, View_employee.\"tel_number\" AS View_employee_tel_number,
View_employee.\"kruzhok\" AS View_employee_kruzhok, View_employee.\"groups\" AS
View_employee_groups FROM \"dbo\".\"View_employee\" View_employee";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
}
catch(Exception e){
e.printStackTrace();
}
}
}
pst.close();
}
catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
}
while(rs.next()){
String position = rs.getString("position");
jComboBox1.addItem(position);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
while(rs.next()){
String kruzhok = rs.getString("kruzhok");
jComboBox2.addItem(kruzhok);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
private void open_jComboBox3(){
try {
String sql= "Select *from [group]";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
String groups = rs.getString("groups");
jComboBox3.addItem(groups);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
/**
* @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(sotr.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(sotr.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(sotr.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(sotr.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
}
//</editor-fold>
stored_pro.setString(1, this.jTextField2.getText());
stored_pro.setString(2, this.jTextField3.getText());
stored_pro.setString(3, this.jTextField4.getText());
stored_pro.setString(4, this.jTextField5.getText());
stored_pro.setString(5, this.jTextField6.getText());
stored_pro.setString(6, (String)this.jComboBox2.getSelectedItem());
stored_pro.setString(7, (String)this.jComboBox3.getSelectedItem());
stored_pro.setString(8, (String)this.jComboBox4.getSelectedItem());
stored_pro.execute();
JOptionPane.showMessageDialog(null, "Saved");
jComboBox2.setSelectedItem(null);
jComboBox3.setSelectedItem(null);
jComboBox4.setSelectedItem(null);
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
UpdateJTable();
}
Кнопка «Удалить»
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
conn = Shop.connect();
stored_pro = conn.prepareCall("{call delete_child (?)}");
stored_pro.setString(1, this.jTextField1.getText());
stored_pro.execute();
JOptionPane.showMessageDialog(null, "Deleted");
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
UpdateJTable();
}
Кнопка «Обновить»
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
conn = Shop.connect();
stored_pro = conn.prepareCall("{call update_child (?,?,?,?,?,?,?,?,?)}");
stored_pro.setString(1, this.jTextField1.getText());
stored_pro.setString(2, this.jTextField2.getText());
stored_pro.setString(3, this.jTextField3.getText());
stored_pro.setString(4, this.jTextField3.getText());
stored_pro.setString(5, this.jTextField5.getText());
stored_pro.setString(6, this.jTextField6.getText());
stored_pro.setString(7, (String)this.jComboBox2.getSelectedItem());
stored_pro.setString(8, (String)this.jComboBox3.getSelectedItem());
stored_pro.setString(9, (String)this.jComboBox4.getSelectedItem());
stored_pro.execute();
JOptionPane.showMessageDialog(null, "Updated");
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
UpdateJTable();
}
Отчет создается в таком же порядке как в сотудниках, в такой же последовательности
Код для запроса в отчете:
select View_children.id as View_children_id, View_children.FIO as View_children_FIO,
View_children.dateborn as View_children_dateborn, View_children.addres as View_children_addres,
View_children.tel_dad as View_children_tel_dad, View_children.tel_mom as View_children_tel_mom,
View_children.groups as View_children_groups, View_children.kruzhok as View_children_kruzhok,
View_children.nationality as View_children_nationality from dbo.View_children as View_children
Кнопка «посмотреть отчет»
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
showMeAllReport() }
сам метод:
}
catch(Exception e){
e.printStackTrace();
}
}
Кнопка «отчет по №»
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
showById();
}
Сам метод:
private void showById(){
try{
conn = Shop.connect();
JasperDesign jasperDesign = JRXmlLoader.load("C:\\Users\\Zapadai\\Documents\\NetBeansProjects\\
Shop\\src\\shop\\report4.jrxml");
String sql = "SELECT View_children.\"id\" AS View_children_id, View_children.\"FIO\" AS
View_children_FIO, View_children.\"dateborn\" AS View_children_dateborn, View_children.\"address\" AS
View_children_address, View_children.\"tel_dad\" AS View_children_tel_dad, View_children.\"tel_mom\" AS
View_children_tel_mom, View_children.\"groups\" AS View_children_groups, View_children.\"kruzhok\" AS
View_children_kruzhok, View_children.\"nationality\" AS View_children_nationality
FROM \"dbo\".\"View_children\" View_children WHERE View_children.\"id\"="+ this.jTextField7.getText();
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
}
catch(Exception e){
e.printStackTrace();
}
}
5. Создание графика
Пропишем код на кнопку «Просмотр графика»
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(35, "Marks", "Отсутствует(не посещают)");
dataset.setValue(20, "Marks", "Шахматы");
dataset.setValue(65, "Marks", "Танцы");
JFreeChart chart =ChartFactory.createBarChart("Количество посещений кружков ",
"Наименование кружков", "Количество посещений в %", dataset, PlotOrientation.VERTICAL, false,
true, false);
CategoryPlot p=chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.black);
ChartFrame frame = new ChartFrame("График", chart);
frame.setVisible(true);
frame.setSize(650,550);
}
/**
* 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">
private void initComponents() {
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jTable1MousePressed(evt);
}
});
jScrollPane1.setViewportView(jTable1);
jLabel4.setText("Адресс");
jLabel5.setText("телефон папы");
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
jButton1.setText("Добавить ");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Обновить данные");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("удалить запись");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jLabel7.setText("Кружок");
jLabel2.setText("№");
jLabel8.setText("Группа");
jLabel3.setText("ФИО");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jLabel10.setText("Национальность");
jButton5.setText("отчет по №");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
pack();
}// </editor-fold>
private void UpdateJTable(){
try{
conn = Shop.connect();
String sql = "SELECT * FROM [View_children]";
statement = conn.createStatement();
rs = statement.executeQuery(sql);
this.jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e){
e.printStackTrace();
}
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
UpdateJTable();
open_jComboBox2();
open_jComboBox3();
open_jComboBox4();
jComboBox2.setSelectedItem(null);
jComboBox3.setSelectedItem(null);
jComboBox4.setSelectedItem(null);
}
stored_pro.setString(1, this.jTextField2.getText());
stored_pro.setString(2, this.jTextField3.getText());
stored_pro.setString(3, this.jTextField4.getText());
stored_pro.setString(4, this.jTextField5.getText());
stored_pro.setString(5, this.jTextField6.getText());
stored_pro.setString(6, (String)this.jComboBox2.getSelectedItem());
stored_pro.setString(7, (String)this.jComboBox3.getSelectedItem());
stored_pro.setString(8, (String)this.jComboBox4.getSelectedItem());
stored_pro.execute();
JOptionPane.showMessageDialog(null, "Saved");
jComboBox2.setSelectedItem(null);
jComboBox3.setSelectedItem(null);
jComboBox4.setSelectedItem(null);
}catch(Exception e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
UpdateJTable();
}
while(rs.next()){
String groups = rs.getString("groups");
jComboBox2.addItem(groups);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
while(rs.next()){
String kruzhok = rs.getString("kruzhok");
jComboBox3.addItem(kruzhok);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
private void open_jComboBox4(){
try {
String sql= "Select *from nationality";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
String nationality = rs.getString("nationality");
jComboBox4.addItem(nationality);
}
}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
private void showMeAllReport(){
try{
conn = Shop.connect();
JasperDesign jasperDesign = JRXmlLoader.load("C:\\Users\\Zapadai\\Documents\\
NetBeansProjects\\Shop\\src\\shop\\report3.jrxml");
String sql = "SELECT View_children.\"id\" AS View_children_id, View_children.\"FIO\" AS
View_children_FIO, View_children.\"dateborn\" AS View_children_dateborn,
View_children.\"address\" AS View_children_address, View_children.\"tel_dad\" AS
View_children_tel_dad, View_children.\"tel_mom\" AS View_children_tel_mom,
View_children.\"groups\" AS View_children_groups, View_children.\"kruzhok\" AS
View_children_kruzhok, View_children.\"nationality\" AS View_children_nationality
FROM \"dbo\".\"View_children\" View_children";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
}
catch(Exception e){
e.printStackTrace();
}
}
private void showById(){
try{
conn = Shop.connect();
JasperDesign jasperDesign = JRXmlLoader.load("C:\\Users\\Zapadai\\Documents\\
NetBeansProjects\\Shop\\src\\shop\\report4.jrxml");
String sql = "SELECT View_children.\"id\" AS View_children_id, View_children.\"FIO\" AS
View_children_FIO, View_children.\"dateborn\" AS View_children_dateborn,
View_children.\"address\" AS View_children_address, View_children.\"tel_dad\" AS
View_children_tel_dad, View_children.\"tel_mom\" AS View_children_tel_mom,
View_children.\"groups\" AS View_children_groups, View_children.\"kruzhok\" AS
View_children_kruzhok, View_children.\"nationality\" AS View_children_nationality
FROM \"dbo\".\"View_children\" View_children WHERE View_children.\"id\"="+
this.jTextField7.getText();
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
}
catch(Exception e){
e.printStackTrace();
}
}
/**
* @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(tovar.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(tovar.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(tovar.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(tovar.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 692, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(238, 238, 238)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(35, 35, 35)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @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(nursery.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(nursery.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(nursery.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(nursery.class.getName()).log(java.util.logging
.Level.SEVERE, null, ex);
}
//</editor-fold>
Форма provider.java
Полный листинг provider.java
package shop;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.proteanit.sql.DbUtils;
/**
*
* @author Zapadai
*/
public class provider extends javax.swing.JFrame {
Connection conn = null;
CallableStatement stored_pro = null;
Statement statement = null;
ResultSet rs = null;
/**
* Creates new form provider
*/
public provider() {
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">
private void initComponents() {
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
pack();
}// </editor-fold>
/**
* @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(provider.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(provider.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(provider.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(provider.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
Форма providers.java
Полный листинг кода providers.java
package shop;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import net.proteanit.sql.DbUtils;
/**
*
* @author Zapadai
*/
public class remainders extends javax.swing.JFrame {
Connection conn = null;
CallableStatement stored_pro = null;
Statement statement = null;
ResultSet rs = null;
/**
* Creates new form remainders
*/
public remainders() {
initComponents();
}
private void UpdateJTable(){
try{
conn = Shop.connect();
String sql = "SELECT * FROM [View_id1]";
statement = conn.createStatement();
rs = statement.executeQuery(sql);
this.jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e){
e.printStackTrace();
}
}
/**
* 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">
private void initComponents() {
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(jTable1);
pack();
}// </editor-fold>
/**
* @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(remainders.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(remainders.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(remainders.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(remainders.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>