Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

sql - 在jTable中将超链接添加到sql的单个值(Adding a hyperlink to a single value of sql in jTable)

I am implementing a search interface in eclipse with the help of mysql.

(我正在mysql的帮助下在Eclipse中实现搜索界面。)

My search interface yields the results I want, but I want to be able to have the "video_url" column clickable and bring up a hyperlink.

(我的搜索界面会产生我想要的结果,但我希望能够单击“ video_url”列并显示一个超链接。)

Is there a way to do this for a single column?

(有没有办法对单个列执行此操作?)

Right now the Jtable is "editable", so the user can click on it, but no changes are made to it.

(现在,Jtable是“可编辑的”,因此用户可以单击它,但不对其进行任何更改。)

The link can be copied and then pasted later, but I'm really trying to have the link be opened from the interface.

(可以复制链接,然后再粘贴,但是我实际上是想从界面中打开链接。)

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    VIdeo_search_test window = new VIdeo_search_test();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public VIdeo_search_test() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 17));
        frame.setBounds(400, 400, 1050, 1000);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JLabel lblVideoSearch = new JLabel("Video Search");
        lblVideoSearch.setFont(new Font("Tahoma", Font.PLAIN, 19));
        lblVideoSearch.setBounds(241, 11, 230, 27);
        frame.getContentPane().add(lblVideoSearch);

        JButton btnSearchCity = new JButton("Search City");
        btnSearchCity.setBounds(216, 80, 165, 25);
        btnSearchCity.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {


                DefaultTableModel model = new DefaultTableModel(new String[]{"video_url", "video name", "video description", "video_city", "video_subject", "video_tags", "reviewed_by", "star"}, 0);


try {

                    Class.forName("com.mysql.cj.jdbc.Driver");
                    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/userdatabase", "root", "pass1234");

                    Statement stmt= con.createStatement();
                    String sql = "Select * from video where video_city = '" +txtCity.getText()+"'";
                    ResultSet rs=stmt.executeQuery(sql);
                    while(rs.next())
                    {
                         String a = rs.getString("video_url");
                         String d = rs.getString("video_name");
                         String e = rs.getString("video_description");
                         String f = rs.getString("video_city");
                         String g = rs.getString("video_subject");
                         String h = rs.getString("video_tags");
                         String k = rs.getString("reviewed_by");
                         String i = rs.getString("star");
                         model.addRow(new Object[]{a, d, e, f, g, h, k, i});

                            table.setModel(model);

                              }
                                {

                               con.close();}
                    } catch(Exception e) {System.out.print (e);}

            }
        });
        frame.getContentPane().add(btnSearchCity);

        JButton btnSearchTag = new JButton("Search Tag");
        btnSearchTag.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                DefaultTableModel model = new DefaultTableModel(new String[]{"video_url", "video name", "video description", "video_city", "video_subject", "video_tags", "reviewed_by", "star"}, 0);


                try {

                                    Class.forName("com.mysql.cj.jdbc.Driver");
                                    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/userdatabase", "root", "pass1234");

                                    Statement stmt= con.createStatement();
                                    String sql = "Select * from video where video_tags LIKE '"+txtTag.getText()+"%'";
                                    ResultSet rs=stmt.executeQuery(sql);
                                    while(rs.next())
                                    {
                                                String a = rs.getString("video_url");
                                                String d = rs.getString("video_name");
                                                String e = rs.getString("video_description");
                                                String f = rs.getString("video_city");
                                                String g = rs.getString("video_subject");
                                                String h = rs.getString("video_tags");
                                                String k = rs.getString("reviewed_by");
                                                String i = rs.getString("star");
                                                model.addRow(new Object[]{a, d, e, f, g, h, k, i});

                                            table_1.setModel(model);

                                              }
                                    {                                       


                                               con.close();}
                                    } catch(Exception e) {System.out.print (e);}

                            }



        });
        btnSearchTag.setBounds(216, 303, 165, 25);
        frame.getContentPane().add(btnSearchTag);

        txtCity = new JTextField();
        txtCity.setBounds(216, 49, 165, 20);
        frame.getContentPane().add(txtCity);
        txtCity.setColumns(10);

        table = new JTable();
        table.setBounds(10, 116, 867, 135);
        frame.getContentPane().add(table);

        txtTag = new JTextField();
        txtTag.setColumns(10);
        txtTag.setBounds(216, 272, 165, 20);
        frame.getContentPane().add(txtTag);

        table_1 = new JTable();
        table_1.setBounds(10, 341, 601, 135);
        frame.getContentPane().add(table_1);

        JButton btnViewVideo = new JButton("View Video");
        btnViewVideo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {

                registered_video_interface info = new registered_video_interface();
                registered_video_interface.main(null); }


        });
        btnViewVideo.setBounds(251, 509, 89, 23);
        frame.getContentPane().add(btnViewVideo);
    }
}
  ask by Tengu translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...