Help! I can't do anything with my database even though i've connected!

Hello,
I think I have properly connected to my MS SQL Server 2000 database, cause I'm not throwing any exceptions when I connect, but I can't insert or update any data, it displays error messages when i try to do either..i haven't tested delete cause its a database with empty tables. I think something has to be wrong iwth my database, cause this code works fine when i use jdbc-odbc with MS ACCESS 2000. I'll post my code here, just in case.
<code>
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.sql.*;
import java.rmi.*;
import javax.swing.text.*;
import java.net.InetAddress;
public class mygui extends JPanel implements ActionListener, DocumentListener
//creates a frame object to add the application GUI components to.
private JFrame mgframe;
//text fields and text areas for user input
// private JTextField file;
private JTextField function;
private JTextArea description;
private JTextField context;
private JTextField actions;
private JTextArea name;
private JTextArea type;
private JTextArea arguments;
private JTextArea rvalues;
private JTextArea rvdescrip;
private JTextArea rvnotes;
private JTextArea notes;
private JTextArea funccalled;
//scrollpanes for text areas
private JScrollPane sdescription;
private JScrollPane sname;
private JScrollPane stype;
private JScrollPane sarguments;
private JScrollPane srvalues;
private JScrollPane srvdescrip;
private JScrollPane srvnotes;
private JScrollPane snotes;
private JScrollPane sfunccalled;
// private JLabel lfile;
private JLabel lfunction;
private JLabel ldescription;
private JLabel lcontext;
private JLabel lactions;
private JLabel lname;
private JLabel ltype;
private JLabel larguments;
private JLabel lrvalues;
private JLabel lrvdescrip;
private JLabel lrvnotes;
private JLabel lnotes;
private JLabel lfunccalled;
//buttons
private JButton load;
private JButton savenew;
private JButton newreturncode;
private JButton update;
private JButton delete;
private JButton deletereturncode;
private JButton prev;
private JButton next;
//panels
private JPanel filep;
private JPanel mainp;
private JPanel mainp2;
//documents
private Document insource;
private Document upsource;
private Document delsource;
//strings which contain inputted function information
private String functionname;
private String descriptionname;
private String rvvaluesname;
private String rvdescripname;
private String notesname;
//class constructor that builds the necessary labels
//and text fields, buttons, and panels.
public mygui()
JFrame mgframe = new JFrame("Welcome to the U_Fec function database");
// Closes from title bar
//and from menu
mgframe.addWindowListener(new WindowAdapter()
     public void windowClosing(WindowEvent e)
          System.exit(0);
mgframe.getContentPane().setLayout(new BorderLayout());
mgframe.setBackground(Color.white);
mgframe.setSize(800,999);
mgframe.setVisible(true);
//intializes text fields
// file = new JTextField();
function = new JTextField ();
description = new JTextArea();
context = new JTextField();
actions = new JTextField();
name = new JTextArea();
type = new JTextArea();
arguments = new JTextArea();
rvalues = new JTextArea();
rvdescrip = new JTextArea();
rvnotes = new JTextArea();
notes = new JTextArea();
funccalled = new JTextArea();
//scrollpanes for each text area
sdescription = new JScrollPane(description);
sname = new JScrollPane(name);
stype = new JScrollPane(type);
sarguments = new JScrollPane(arguments);
srvalues = new JScrollPane(rvalues);
srvdescrip = new JScrollPane(rvdescrip);
srvnotes = new JScrollPane(rvnotes);
snotes = new JScrollPane(notes);
sfunccalled = new JScrollPane(funccalled);
//initializes labels for text fields
// lfile = new JLabel("File: ");
lfunction = new JLabel("Function: ");
ldescription = new JLabel ("Description: ");
lcontext = new JLabel ("Context: ");
lactions = new JLabel ("Actions: ");
lname = new JLabel ("Name: ");
ltype = new JLabel ("Type: ");
larguments = new JLabel ("Arguments: ");
lrvalues = new JLabel ("Return Values: ");
lrvdescrip = new JLabel ("Description: ");
lrvnotes = new JLabel ("Notes: ");
lnotes = new JLabel ("Notes: ");
lfunccalled = new JLabel ("Functions called: ");
//initialize buttons
load = new JButton("Load");
update = new JButton ("Update");
savenew = new JButton ("Insert new function");
newreturncode = new JButton ("Insert new return code for existing function");
delete = new JButton ("Del");
deletereturncode = new JButton ("Delete return code");
prev = new JButton ("Prev");
next = new JButton ("Next");
//calls methods to build each panel
buildFilePanel();
buildMainPanel();
//places panel info into correct border location
mgframe.getContentPane().add (filep, BorderLayout.NORTH);
mgframe.getContentPane().add (mainp, BorderLayout.CENTER);
mgframe.getContentPane().add (mainp2,BorderLayout.SOUTH);
private void buildMainPanel()
//main panel
     mainp = new JPanel();
     //Sets color and layout.
     //Adds text fields and labels for user input
     mainp.setBackground(Color.white);
     mainp.setLayout ( new GridLayout (6, 2, 2, 2));
     //grid of name, type, argument, return values,
//return values description, and return value
//notes, which is contained within the main panel
mainp2 = new JPanel();
mainp2.setBackground(Color.white);
mainp2.setLayout( new GridLayout (4, 3, 5, 5));
mainp2.add(lname);
mainp2.add(ltype);
mainp2.add(larguments);
mainp2.add(sname);
mainp2.add(stype);
mainp2.add(sarguments);
mainp2.add(lrvalues);
mainp2.add(lrvdescrip);
mainp2.add(lrvnotes);
mainp2.add(srvalues);
mainp2.add(srvdescrip);
mainp2.add(srvnotes);
// mainp.add(lfunction);
//     mainp.add(function);
mainp.add(lfunction);
mainp.add(function);
     mainp.add(ldescription);
     mainp.add(sdescription);
     mainp.add(lcontext);
     mainp.add(context);
     mainp.add(lactions);
     mainp.add(actions);
mainp.add(lnotes);
mainp.add(snotes);
mainp.add(lfunccalled);
mainp.add(sfunccalled);
     //sets border around panel and a title
     mainp.setBorder(BorderFactory.createTitledBorder("function information"));
     //listeners for each text field and text area
//adds property for eact text area/field
     function.getDocument().addDocumentListener(this);
function.getDocument().putProperty("name","function");
     description.getDocument().addDocumentListener(this);
description.getDocument().putProperty("name", "description");
     context.getDocument().addDocumentListener(this);
     context.getDocument().putProperty("name","context");
actions.getDocument().addDocumentListener(this);
     actions.getDocument().putProperty("name","actions");
name.getDocument().addDocumentListener(this);
     name.getDocument().putProperty("name","name");
type.getDocument().addDocumentListener(this);
     type.getDocument().putProperty("name","type");
arguments.getDocument().addDocumentListener(this);
arguments.getDocument().putProperty("name","arguments");
     rvalues.getDocument().addDocumentListener(this);
rvalues.getDocument().putProperty("name","return values");
rvdescrip.getDocument().addDocumentListener(this);
rvdescrip.getDocument().putProperty("name","return values description");
rvnotes.getDocument().addDocumentListener(this);
rvnotes.getDocument().putProperty("name","return values notes");
notes.getDocument().addDocumentListener(this);
notes.getDocument().putProperty("name","notes");
funccalled.getDocument().addDocumentListener(this);
funccalled.getDocument().putProperty("name","functions called");
private void buildFilePanel ()
     filep = new JPanel();
     //Sets color and layout
     //Adds text field and buttons for file input
     filep.setBackground(Color.white);
     filep.setLayout(new GridLayout(2,3,0,5));
     //Adds each component to the panel
     filep.add(load);
     filep.add(update);
     filep.add(savenew);
filep.add(newreturncode);
filep.add(delete);
filep.add(deletereturncode);
     //filep.add(prev);
//     filep.add(next);
     //sets border around panel
     filep.setBorder(BorderFactory.createTitledBorder("buttons"));
     //adds an actionListener for file name
//     file.getDocument().addDocumentListener(this);
     //sets border around buttons
     load.setBorder(BorderFactory.createRaisedBevelBorder());
     savenew.setBorder(BorderFactory.createRaisedBevelBorder());
newreturncode.setBorder(BorderFactory.createRaisedBevelBorder());
     update.setBorder(BorderFactory.createRaisedBevelBorder());
delete.setBorder(BorderFactory.createRaisedBevelBorder());
deletereturncode.setBorder(BorderFactory.createRaisedBevelBorder());
//     prev.setBorder(BorderFactory.createRaisedBevelBorder());
//     next.setBorder(BorderFactory.createRaisedBevelBorder());
     //listeners for the buttons
     load.addActionListener(this);
     savenew.addActionListener(this);
newreturncode.addActionListener(this);
update.addActionListener(this);
     delete.addActionListener(this);
deletereturncode.addActionListener(this);
//     prev.addActionListener(this);
//     next.addActionListener(this);
public void actionPerformed(java.awt.event.ActionEvent evt)
String dataSourceName = "db1";
String dbURL = "jdbc:odbc:" + dataSourceName;
try{
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver() );
//Driver d = (Driver)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver ");
} catch (Exception e) {
System.out.println(e.getMessage());
// } catch (SQLException e) {
// System.out.println(e.getMessage());
try{
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://NJ8650MONDAL", "m", "m");
Statement stmt = con.createStatement();
if (evt.getSource()==load)
try{
ResultSet result = stmt.executeQuery("SELECT * FROM function_description, return_code_description " + "WHERE function_description.Function = return_code_description.Function_Name AND (((Function)='"+ functionname + "'));");
result.next();
function.setText(result.getString("Function"));
description.setText(result.getString("Description"));
notes.setText(result.getString("Notes"));
rvalues.setText(result.getString("Return_Codes"));
rvdescrip.setText(result.getString("Return_Codes_Description"));
}catch (Exception e) {function.setText("Record not found in database.");}
if(evt.getSource() == update)
try{
con.setAutoCommit(false);
PreparedStatement updateDesc = con.prepareStatement("UPDATE function_description SET Description = ? WHERE Function LIKE ?");
updateDesc.setString(1, descriptionname);
updateDesc.setString(2, functionname);
updateDesc.executeUpdate();
PreparedStatement updateNote = con.prepareStatement("UPDATE function_description SET Notes = ? WHERE Function LIKE ?");
updateNote.setString(1, notesname);
updateNote.setString(2, functionname);
updateNote.executeUpdate();
con.commit();
con.setAutoCommit(true);
con.setAutoCommit(false);
PreparedStatement updateRvalue = con.prepareStatement("UPDATE return_code_description SET Return_Codes = ? WHERE Function_Name LIKE ?");
updateRvalue.setString(1, rvvaluesname);
updateRvalue.setString(2, functionname);
updateRvalue.executeUpdate();
PreparedStatement updateRvdesc = con.prepareStatement("UPDATE return_code_description SET Return_Codes_Description = ? WHERE Function_Name LIKE ?");
updateRvdesc.setString(1, rvdescripname);
updateRvdesc.setString(2, functionname);
updateRvdesc.executeUpdate();
con.commit();
con.setAutoCommit(true);
}catch (Exception e) {function.setText("Could not update function.  Make sure record is found in database");}
if(evt.getSource()==savenew)
try{
con.setAutoCommit(false);
// PreparedStatement insertRvalues = con.prepareStatement("INSERT INTO return_code_description VALUES (?,?,?)");
// insertRvalues.setString(1,functionname);
// insertRvalues.setString(2,rvvaluesname);
// insertRvalues.setString(3,rvdescripname);
// insertRvalues.execute();
PreparedStatement insertFvalues = con.prepareStatement("INSERT INTO function_description VALUES (?,?,?)");
insertFvalues.setString(1,functionname);
insertFvalues.setString(2,descriptionname);
insertFvalues.setString(3,notesname);
insertFvalues.execute();
insertFvalues.close();
PreparedStatement insertRvalues = con.prepareStatement("INSERT INTO return_code_description (Function_Name, Return_Codes, Return_Codes_Description) VALUES (?,?,?)");
insertRvalues.setString(1,functionname);
insertRvalues.setString(2,rvvaluesname);
insertRvalues.setString(3,rvdescripname);
insertRvalues.execute();
con.commit();
con.setAutoCommit(true);
insertRvalues.close();
}catch (Exception e) {function.setText("Could not create new record.  Make sure it is not already there.");}
insertRvalues.setString(1, functionname);
insertRvalues.setString(2, rvdescripname);
insertRvalues.setString(3, rvvaluesname);
insertRvalues.executeUpdate();
con.commit();
con.setAutoCommit(true);
// stmt.executeUpdate("INSERT INTO function_description" + "(Function, Description, Notes)" +
// "VALUES (('"+ functionname + "'), ('"+ descriptionname + "'), ('"+ notesname + "'));");
String sql = "INSERT INTO function_description" +
" (Function, Description, Notes)" +
" VALUES (functionnname, descriptionname, notesname)";
                    stmt.executeUpdate(sql);
String sql2 = "INSERT INTO return_codes_description" +
"(Function Name, Return Codes, Return Codes Description" +
" VALUES (functionname, rvaluesname, rvdescripname)";
stmt.executeUpdate(sql2);
if (evt.getSource() == newreturncode)
try{
PreparedStatement insertnewRvalues = con.prepareStatement("INSERT INTO return_code_description (Function_Name, Return_Codes, Return_Codes_Description) VALUES (?,?,?)");
insertnewRvalues.setString(1,functionname);
insertnewRvalues.setString(2,rvvaluesname);
insertnewRvalues.setString(3,rvdescripname);
insertnewRvalues.execute();
}catch (Exception e){function.setText("Could not add new return code.  Make sure function record exists.");}
if (evt.getSource() == delete)
int n = JOptionPane.showConfirmDialog(mgframe,"Do you want to delete '"+ functionname + "'",
"An Important Question",
JOptionPane.YES_NO_OPTION);
if(n== JOptionPane.YES_OPTION)
try{
con.setAutoCommit(false);
PreparedStatement rDelete = con.prepareStatement("Delete from return_code_description where Function_Name = ?");
rDelete.setString(1, functionname);
int deleteCount2 = rDelete.executeUpdate();
PreparedStatement fDelete = con.prepareStatement("Delete from function_description where Function =? ");
fDelete.setString(1, functionname);
int deleteCount = fDelete.executeUpdate();
con.commit();
con.setAutoCommit(true);
}catch (Exception e) {function.setText("Could not delete record.  Make sure it is in database.");}
if (evt.getSource()== deletereturncode)
try{
PreparedStatement rDelete = con.prepareStatement("Delete from return_code_description where Function_Name = ?");
rDelete.setString(1, functionname);
int deleteCount2 = rDelete.executeUpdate();
}catch (Exception e){function.setText("Could not add new return code.  Make sure function record exists.");}
if (evt.getSource() == next)
try{
ResultSet result = stmt.executeQuery("SELECT * FROM function_description, return_code_description " + "WHERE function_description.Function = return_code_description.Function_Name AND (((Function)='"+ functionname + "'));");
result.next();
result.next();
function.setText(result.getString("Function"));
description.setText(result.getString("Description"));
notes.setText(result.getString("Notes"));
rvalues.setText(result.getString("Return_Codes"));
rvdescrip.setText(result.getString("Return_Codes_Description"));
}catch (Exception e) {function.setText("Record not found in database.");}
*/} catch (SQLException e) {System.out.println(e.getMessage());}
public static void main (String [] args)
mygui mg = new mygui();
//The following 3 methods are DocumentListener methods
public void insertUpdate(javax.swing.event.DocumentEvent evt)
updateLog (evt, "inserted into");
public void changedUpdate (javax.swing.event.DocumentEvent evt)
//not fired by plain text components
public void removeUpdate(javax.swing.event.DocumentEvent evt)
updateLog(evt, "removed from");
public void updateLog(javax.swing.event.DocumentEvent evt, String ac)
Document doc = evt.getDocument();
if( doc.getProperty("name") == "function")
try{
functionname = doc.getText(0,doc.getLength());
}catch (BadLocationException ble) {
// Shouldn't get here
else if ( doc.getProperty("name") == "description")
try{
descriptionname = doc.getText(0,doc.getLength());
}catch (BadLocationException ble) {
// Shouldn't get here
else if ( doc.getProperty("name") == "notes")
try{
notesname = doc.getText(0,doc.getLength());
}catch (BadLocationException ble) {
// Shouldn't get here
else if ( doc.getProperty("name") == "return values")
try{
rvvaluesname = doc.getText(0,doc.getLength());
}catch (BadLocationException ble) {
// Shouldn't get here
else if ( doc.getProperty("name") == "return values description")
try{
rvdescripname = doc.getText(0,doc.getLength());
}catch (BadLocationException ble) {
// Shouldn't get here
//Closes class
</code>
Thanks in advance!!!!

This error message is explained on MSDN site (Article Q313181). Here is an excerpt:
SYMPTOMS
While using the Microsoft SQL Server 2000 Driver for JDBC, you may experience the following exception:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
CAUSE
This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (AutoCommit=false) and while using the direct (SelectMethod=direct) mode. Direct mode is the default mode for the driver.
RESOLUTION
When you use manual transaction mode, you must set the SelectMethod property of the driver to Cursor, or make sure that you use only one active statement on each connection as specified in the "More Information" section of this article.

Similar Messages

Maybe you are looking for