X
Xarky
Hi,
I have the following code:
public class DatabaseManager
{
private Connection con;
private Statement stmt;
public DatabaseManager()
{
try
{
System.setProperty("myDataSource",
"c:/practicals/jdbc/database");
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
} // end try
catch(ClassNotFoundException e)
{
System.out.println ("errors");
}
} // end constructor
public void connection()
{
try
{
con = DriverManager.getConnection("jdbc
dbc:myDataSource","","");
stmt = con.createStatement();
// creating the table - can be created only once
stmt.execute("create table HoursLog ("+" programmer varchar(32),"+ "
day char (3)," + "hours integer);");
// populating the table
stmt.execute("insert into HoursLog values ('Pete', 'Mon', 2);");
stmt.execute("insert into HoursLog values ('Steve', 'Mon', 4);");
stmt.execute("insert into HoursLog values ('Wally', 'Tue', 8);");
stmt.execute("insert into HoursLog values ('Molly', 'Mon', 9);");
stmt.execute("insert into HoursLog values ('Pete', 'Thu', 3);");
System.out.println ("table populated");
} // end try statment
catch(SQLException e)
{
System.out.println ("Problems executing statment\n");
System.exit(-1);
} // end catch statment
} // end method connection
public void Transactions()
{
try
{
ResultSet result;
int data;
result = stmt.executeQuery ("SELECT hours FROM HoursLog WHERE
programmer='Pete';");
data = result.getInt("hours");
data = data - 2;
con.setAutoCommit(true);
stmt.executeUpdate ("UPDATE HoursLog SET hours = data WHERE
programmer= 'Pete'");
con.setAutoCommit(false);
} // end try statment
catch(SQLException e)
{
System.out.println ("Problems executing statment\n"+e.toString());
System.exit(-1);
} // end catch statment
} // end method Transactions
} // end class
DatabaseManager myDB = new DatabaseManager();
myDB.connection();
myDB.Transactions();
My problem is in method Transactions. It is giving me an error on
line
data = result.getInt("hours");
What I am trying to do is getting the number of hours of Pete, and
reducing it by 2.
Error given is- "java.sql.SQLException: [Microsoft][ODBC Driver
Manager] Invalid cursor state"
Can someone help me solve my problem
Thanks in Advance
I have the following code:
public class DatabaseManager
{
private Connection con;
private Statement stmt;
public DatabaseManager()
{
try
{
System.setProperty("myDataSource",
"c:/practicals/jdbc/database");
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
} // end try
catch(ClassNotFoundException e)
{
System.out.println ("errors");
}
} // end constructor
public void connection()
{
try
{
con = DriverManager.getConnection("jdbc
stmt = con.createStatement();
// creating the table - can be created only once
stmt.execute("create table HoursLog ("+" programmer varchar(32),"+ "
day char (3)," + "hours integer);");
// populating the table
stmt.execute("insert into HoursLog values ('Pete', 'Mon', 2);");
stmt.execute("insert into HoursLog values ('Steve', 'Mon', 4);");
stmt.execute("insert into HoursLog values ('Wally', 'Tue', 8);");
stmt.execute("insert into HoursLog values ('Molly', 'Mon', 9);");
stmt.execute("insert into HoursLog values ('Pete', 'Thu', 3);");
System.out.println ("table populated");
} // end try statment
catch(SQLException e)
{
System.out.println ("Problems executing statment\n");
System.exit(-1);
} // end catch statment
} // end method connection
public void Transactions()
{
try
{
ResultSet result;
int data;
result = stmt.executeQuery ("SELECT hours FROM HoursLog WHERE
programmer='Pete';");
data = result.getInt("hours");
data = data - 2;
con.setAutoCommit(true);
stmt.executeUpdate ("UPDATE HoursLog SET hours = data WHERE
programmer= 'Pete'");
con.setAutoCommit(false);
} // end try statment
catch(SQLException e)
{
System.out.println ("Problems executing statment\n"+e.toString());
System.exit(-1);
} // end catch statment
} // end method Transactions
} // end class
DatabaseManager myDB = new DatabaseManager();
myDB.connection();
myDB.Transactions();
My problem is in method Transactions. It is giving me an error on
line
data = result.getInt("hours");
What I am trying to do is getting the number of hours of Pete, and
reducing it by 2.
Error given is- "java.sql.SQLException: [Microsoft][ODBC Driver
Manager] Invalid cursor state"
Can someone help me solve my problem
Thanks in Advance