I have wrote this small program to connect to a database using a JTDS ODBC driver and it seems to be finding the driver and all but I dont think its connecting to the database can some please tell me if my code looks ok
import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.sql.*; import javax.swing.*; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JOptionPane; public class Gui extends JFrame { private JComboBox box; private JButton reg; private static String[] filename = {"Sign In", "Sign Out", "Break In", "Break Out", "Lunch In", "Lunch Out"}; public Gui () { super("CAW Time Clock"); setLayout(new FlowLayout()); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:"); box = new JComboBox(filename); reg = new JButton("Submit"); try { //Connecting the driver Class.forName("net.sourceforge.jtds.jdbc.Driver"); Connection conn = DriverManager.getConnection ("jdbc:jtds:sqlserver://DATASERVER1:1433/Time_Log_CSR"); //Inserting the statement to the database Statement statement = conn.createStatement(); statement.executeUpdate(" INSERT INTO TimeLog ( LogDate, Name, LogReason, TimeInOrOut)" + "VALUES (null, washington, null, null)"); } catch ( Exception e ) { e.printStackTrace(); } add(box); add(reg); //get current date time with Date() Date date = new Date(); System.out.println(dateFormat.format(date)); HandlerClass handler = new HandlerClass(); reg.addActionListener(handler); } private class HandlerClass implements ActionListener { public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null, String.format(" Your Time has been recored", event.getActionCommand())); } } }