Hey there,
First question:
I really need help with debugging this code. I keep getting the java.sql.SQLExc eption: General error, and am now lost at a solution to it...I get this with about 4 of my classes and the other 5 classes work fine. Any ideas?
Question 2:
Now I also want to find out, is there a way to extract information from Microsoft Access 2003 and insert it into a specific location in a Microsoft Word 2003 document?
Please assist,
Thanks and Regards,
Donovan
First question:
I really need help with debugging this code. I keep getting the java.sql.SQLExc eption: General error, and am now lost at a solution to it...I get this with about 4 of my classes and the other 5 classes work fine. Any ideas?
Code:
[B]Money.java[/B]
package surveying_reports;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
public class Money extends JFrame
{
JLabel detailsLbl, bankingLbl, oftenLbl, whomLbl, maxLbl;
JComboBox detailsCB, oftenCB, whomCB, maxCB;
String[] details = {"Please select...", "SABS Cat 1", "SABS Cat 2", "SABS Cat 2 HD D3", "SABS Cat 2 ADM", "SABS Cat 2 ADM D3", "SABS Cat 3", "SABS Cat 4"};
String[] often = {"Please select...", "Monthly", "Weekly", "Daily"};
String[] whom = {"Please select...", "Professional Carriers", "Management", "Other"};
String[] max = {"Please select...", "> R 5,000.00", "R 5,000.00 - R 12,500.00", "R 12,500.00 - R 25,000.00", "R25,000.00 - R 50,000.00", "R 50,000.00 - R 75,000.00", "R 75,000.00 - R 100,000.00", "R 100,000.00 - R 200,000.00"};
String detailsS, oftenS, whomS, maxS;
closeMButtonHandler closeMHandler;
JButton mButton;
public Money()
{
setTitle("Money");
// Add Labels
detailsLbl = new JLabel("Details of Safe: ");
detailsLbl.setSize(200,50);
detailsLbl.setLocation(10,10);
bankingLbl = new JLabel("Details of Banking: ");
bankingLbl.setLocation(10,40);
bankingLbl.setSize(200,50);
oftenLbl = new JLabel("How Often: ");
oftenLbl.setSize(200,50);
oftenLbl.setLocation(30,68);
whomLbl = new JLabel("By Whom: ");
whomLbl.setSize(200,40);
whomLbl.setLocation(30,100);
maxLbl = new JLabel("Maximum amount of cash kept on site: ");
maxLbl.setSize(200,40);
maxLbl.setLocation(10,130);
// Add ComboBoxes
detailsCB = new JComboBox(details);
detailsCB.setSize(200,20);
detailsCB.setLocation(175,25);
detailsCB.setMaximumRowCount(4);
oftenCB = new JComboBox(often);
oftenCB.setSize(200,20);
oftenCB.setLocation(175,85);
oftenCB.setMaximumRowCount(4);
whomCB = new JComboBox(whom);
whomCB.setSize(200,20);
whomCB.setLocation(175,110);
whomCB.setMaximumRowCount(4);
maxCB = new JComboBox(max);
maxCB.setSize(200,20);
maxCB.setLocation(175,140);
maxCB.setMaximumRowCount(4);
// Save and Close Button
mButton = new JButton("Save and Close");
mButton.setSize(200,25);
mButton.setLocation(201,190);
closeMHandler = new closeMButtonHandler();
mButton.addActionListener(closeMHandler);
Container mPane = getContentPane();
mPane.setLayout(null);
mPane.add(detailsLbl);
mPane.add(bankingLbl);
mPane.add(oftenLbl);
mPane.add(whomLbl);
mPane.add(maxLbl);
mPane.add(detailsCB);
mPane.add(oftenCB);
mPane.add(whomCB);
mPane.add(maxCB);
mPane.add(mButton);
setContentPane(mPane);
setSize(410,250);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
// Add Save and Close Button and allows functionality
private class closeMButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
try
{
clsSql sqlC = new clsSql();
String strUpdateMoney = "INSERT INTO tblMoney(SafeDetails,Often,Depositer,MaxAmount)" +
" Values('" + detailsCB.getSelectedItem().toString() + "','" + oftenCB.getSelectedItem().toString() + "','" + whomCB.getSelectedItem().toString() + "','" + maxCB.getSelectedItem().toString() + "')";
sqlC.execQuery(strUpdateMoney);
}
catch(Exception e){
e.printStackTrace();
}
setVisible(false);
}
}
}
[B]Calling Class: clsSql.java[/B]
package surveying_reports;
import java.sql.*;
public class clsSql {
Connection connection;
Statement statement;
/** Creates a new instance of clsSql */
public clsSql() throws ClassNotFoundException
{
loadDriver();
}
// Load the Driver
public void loadDriver() throws ClassNotFoundException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
// Make the Connection
public void makeConnection() throws SQLException {
connection=DriverManager.getConnection("jdbc:odbc:tester");
}
public void buildStatement() throws SQLException {
statement = connection.createStatement();
}
public ResultSet getQuery(String strA) throws SQLException {
makeConnection();
buildStatement();
ResultSet set = null;
boolean foundResults =
statement.execute(strA);
if (foundResults = true)
{
set = statement.getResultSet();
}
return set;
}
public void execQuery(String sqlStatement) throws SQLException, ClassNotFoundException{
int i;
Connection Updateconnection;
Statement Updatestatement;
Updateconnection=DriverManager.getConnection("jdbc:odbc:tester");
Updatestatement = Updateconnection.createStatement();
i = Updatestatement.executeUpdate(sqlStatement);
Updateconnection.close();
}
public void closeConnection() throws SQLException {
connection.close();
}
}
Now I also want to find out, is there a way to extract information from Microsoft Access 2003 and insert it into a specific location in a Microsoft Word 2003 document?
Please assist,
Thanks and Regards,
Donovan
Comment