小编Ben*_*rre的帖子

Java中的ExecuteUpdate sql语句不起作用

我正在学习如何在Java中使用SQL.我已经成功安装了JDBC驱动程序,我可以从数据库中读取记录并将其打印在屏幕上.

尝试执行更新或插入语句时,我的问题发生,没有任何反应.这是我的代码:

问题所在的方法

public static void updateSchools(ArrayList<String> newSchool)
{
    try
    {
        openDatabase();
        stmt = c.createStatement();
        int numberOfRows = stmt.executeUpdate("UPDATE schools SET address='abc' WHERE abbreviation='2';");
        System.out.println(numberOfRows);
        closeDatabase();
    }
    catch (Exception e)
    {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        System.exit(0);
    }
}
Run Code Online (Sandbox Code Playgroud)

支持功能

public static void openDatabase()
{
    c = null;
    stmt = null;
    try
    {
        Class.forName("org.postgresql.Driver");
        c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Badminton", "postgres", "postgrespass");
        c.setAutoCommit(false);
    }
    catch (Exception e)
    {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        System.exit(0);
    }
    System.out.println("Database opened successfully");
}

public static …
Run Code Online (Sandbox Code Playgroud)

java sql jdbc

6
推荐指数
1
解决办法
5587
查看次数

POI - 将工作表设置为非常隐藏不起作用

我正在使用 POI 库对 XLS 文件执行一些 Java 代码。我试图将一些工作表设置为非常隐藏,因此用户根本无法访问它们。

非常隐蔽的工作表的定义

http://www.kiranjholla.com/myblog/2010/03/the-very-hidden-sheet-in-excel.html

代码

    // Creates and hides a sheet
    HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
    HSSFSheet hiddenSheet = workbook.createSheet(sheetName);
    workbook.setSheetHidden(workbook.getSheetIndex(sheetName), HSSFWorkbook.SHEET_STATE_VERY_HIDDEN);
Run Code Online (Sandbox Code Playgroud)

问题

不幸的是,当我打开生成的 Excel 文件时,我试图隐藏的工作表显示为隐藏,但用户仍然可以使用格式 -> 工作表 -> 显示选项访问它们。

谢谢你的帮助。

java apache-poi

5
推荐指数
1
解决办法
6534
查看次数

即使未选中复选框,JCheckbox isSelected()也会返回true

JCheckbox虽然我以前经常使用它们,但我遇到了问题.

基本上,我创建一个带有复选框的非常简单的窗口,然后检查它们是否被选中.执行该检查时,JCheckbox即使不是,也会显示为已选中.这是我的代码.要重现我的问题,请运行该项目,然后单击"开始".即使createStatisticsFilesCheckBox设置为未选中,也要从构造函数中检查是否在ActionListener方法中选中它true.提前致谢!

包查询;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Test extends Thread implements ActionListener 
{
    private JButton cancelButton, backButton, startButton;
    private JCheckBox createQueriesCheckBox,createStatisticsFilesCheckBox, createPokerHandIDFilesCheckBox;
    private JFrame frame;

    public void actionPerformed(ActionEvent e)
    {
        if ("Start".equals(e.getActionCommand()))
        {
            if (createQueriesCheckBox.isSelected() == true);
            {
                // Code here
            }

            if (createStatisticsFilesCheckBox.isSelected() == true);
            {
                // Code here
                // Always show as selected …
Run Code Online (Sandbox Code Playgroud)

java swing jcheckbox

1
推荐指数
1
解决办法
9628
查看次数

文件被锁定以进行编辑

我正在做一些编写 Excel 文件的代码。但是,在打开main函数结束时创建的文件时,Open Office 会显示一条错误消息,指出文件被未知用户锁定。我检查了一下,似乎我正在使用该文件关闭对文件和工作簿的所有引用。

在此先感谢您的帮助!

代码

public class StandingsFile
{
    private Workbook workbook;

    public StandingsFile(InputStream inputStream, File outputFile)
    {
        this.outputFile = outputFile;
        workbook = POIExcelFileProcessor.createWorkbook(inputStream);
    }

    public void write()
    {
        // Code where the sheets in the Excel file are modified

        POIExcelFileProcessor.writeWorkbook(workbook, outputFile);
    }

    public static void main(String[] args)
    {
        standingsExcelFile = new StandingsFile(StandingsCreationHelper.class.getResourceAsStream(TEMPLATE_FILENAME), outputFile);
        standingsExcelFile.write();

        try
        {
            Desktop dt = Desktop.getDesktop();
            dt.open(outputFile);
        }
        catch (Exception ex)
        {
            e.printStackTrace();
        }
    }
}

public class POIExcelFileProcessor
{

    public …
Run Code Online (Sandbox Code Playgroud)

java apache-poi

1
推荐指数
1
解决办法
1115
查看次数

使用Swing设置大小问题

我正在尝试使用Swing创建一个非常简单的GUI面板.

这是我的代码:

    JPanel bigBlindSelectionPanel = new JPanel();
    bigBlindSelectionPanel.setLayout(new BorderLayout());
    bigBlindSelectionPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    JList bigBlindList = new JList<String>(model);

    // Code to fill the list

    JLabel bigBlindAddLabel = new JLabel("Add big blind numbers to queries");
    bigBlindAddLabel.setBorder(new EmptyBorder(20, 20, 20, 20));

    JScrollPane bigBlindScrollPanel = new JScrollPane(bigBlindList);
    //bigBlindScrollPanel.setSize(0, 80);
    bigBlindScrollPanel.setBorder(new EmptyBorder(20, 20, 20, 20));

    JButton bigBlindAddButton = new JButton("Add");
    bigBlindAddButton.addActionListener(this);
    //bigBlindAddButton.setSize(0, 20);
    bigBlindAddButton.setBorder(new EmptyBorder(20, 20, 20, 20));

    bigBlindSelectionPanel.add(bigBlindAddLabel, BorderLayout.NORTH);
    bigBlindSelectionPanel.add(bigBlindScrollPanel, BorderLayout.CENTER);
    bigBlindSelectionPanel.add(bigBlindAddButton, BorderLayout.SOUTH);

    frame.pack();
    frame.setSize(300, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(bigBlindSelectionPanel);
    frame.setVisible(true);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这是结果.

我有以下问题:

  1. 如何更改按钮和滚动面板的大小?设置大小操作(在上面的代码中注释)没有产生任何结果.

  2. 如何在不使用setSize()调用指定大小的情况下显示帧?如果我没有以高度和宽度调用setSize方法,则不显示任何内容.我问,因为我已经读过,如果可能的话,我不应该使用尺寸.

在此先感谢您的帮助!

java swing

0
推荐指数
1
解决办法
50
查看次数

标签 统计

java ×5

apache-poi ×2

swing ×2

jcheckbox ×1

jdbc ×1

sql ×1