如何获取jXDatePicker的值并将用户选择的日期存储到oracle数据库中?

时间:2015-03-07 12:13:13

标签: java oracle

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

       if (evt.getSource() == jButton3)
        {
           int x = 0;
           String s1 = jTextField12.getText();
           String s2 = jTextField13.getText(); 
           Date s3 = jXDatePicker15.getDate();//**Here i need a correct code to store the user's selected date into the database**.

  try
     {
      Class.forName("oracle.jdbc.driver.OracleDriver");

  Connection con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "Raju", "1209");
  PreparedStatement ps = con.prepareStatement("insert into NEWFRAME values(?,?,?)");
  ps.setString(1, s1);
  ps.setString(2, s2);
  ps.setDate(3, (java.sql.Date) s3);//Here also i need some correct code.
  ResultSet rs = ps.executeQuery();
  x++;
  if (x > 0) 
            {
             JOptionPane.showMessageDialog(jButton3, "Data Saved Successfully");

          }
        }

catch(Exception ex)            {             的System.out.println(前);             }          }

0 个答案:

没有答案