Java-获取选定列表项的值

时间:2018-06-24 18:17:25

标签: java sql database eclipse user-interface

如何获取列表的值?

这是我的两个列表,从列表中选择这两个值(如标记所示)后,我想在代码的这个位置将这两个元素(字符串)插入数据库:

max

在最后一个位置,我想选择用户在UI两个列表中选择的值:

Picture list

PreparedStatement pst = con.prepareStatement(query); pst.setString(1, txtFieldName.getText()); pst.setString(2, txtFieldNumber.getText()); // pst.setString(3, listDay.); JButton btnNewButton_2 = new JButton("Speichern"); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
try {


    java.sql.Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/dblabor","root",""); 
String query = "INSERT INTO Teach(Prof,Laborname,Room,Day,Time) VALUES(?,?,?,?,?)";
        PreparedStatement pst = con.prepareStatement(query);

`

谢谢大家。

2 个答案:

答案 0 :(得分:2)

  

如何获取列表的值?

已被告知您只需使用:

#!/bin/bash

cd /

echo "1. Basic Details"
echo "2. CPU Information"
echo "3. Network information"
echo "4. All"
echo "5. Cancel"
read option 



if [ $option -eq 1 ];then


    echo ">>>>> Server Name, Date, UPtime <<<<<"
    echo "====================================="
    echo "Date :- `date`"
    echo " "
    echo "Host Name :- `hostname`"
    echo " "
    echo " OS Version"
    oslevel -g
    echo " "
    echo " UPTIME :- "
    uptime
    echo " "
    echo " "

elif [ $option -eq 2 ];then


    echo ">>>>>    CPU and Memory Info.   <<<<<"
    echo "====================================="
    echo " "
    echo 
    echo "          CPU :- `lsdev | grep Processor | wc -l`"
    echo " "
    echo "       Memory :- `lsattr -El mem0 | tail -1`"

    echo " "
    echo " "
    echo "====================================="
    echo ">>>>> Important Kernel Params.  <<<<<"
    echo "====================================="
    echo " "
    echo "****************************************"
    echo " "
    lsattr -El aio0


elif [ $option -eq 3 ];then

    echo ">>>>> Memory Usage Information  <<<<<"

    um=`svmon -G | head -2|tail -1| awk {'print $3'}`
    um=`expr $um / 256`
    tm=`lsattr -El sys0 -a realmem | awk {'print $2'}`
    tm=`expr $tm / 1024`
    fm=`expr $tm - $um`
    ump=`expr $um \* 100`
    ump=`expr $ump / $tm`
    echo " "
    echo "Memory Used :- "$ump"%"
    echo " "
    echo "----------------------";
    echo "Memory Information\n";
    echo "total memory = $tm MB"
    echo "free memory = $fm MB"
    echo "used memory = $um MB"
    echo "-----------------------\n";
    echo " "
    echo " "

else
 echo "Enter correct option"
fi  

您显示值了吗?

您已经阅读了JDBC Database Access上的教程吗?

我相信您需要使用Object value = list.getSelectedValue(); System.out.println(value); 的{​​{1}}方法来更改数据。

答案 1 :(得分:0)

如果使用的是Swing,请尝试方法javax.swing.JList#getSelectedValue从JList对象获取值。