Dear All,
I have a snippet of code as below. Here I build one db connection and is shared across. I can put the dbconn.commit in place and no problem. The problem when I put the dbconn.rollback I get this sort of error "commServer.java:1798: unreported exception java.sql.SQLException; must be caught or declared to be thrown dbconn.rollback();". So where best to put the rollback?
public void run()
{
createConnection();
while (true)
{
try
{
//all my sql statements.
dbconn.commit();
}
catch (Exception e)
{
System.out.println("\nSQL Error here :");
//dbconn.rollback();
e.printStackTrace();
}
}
closeConnection();
}
void createConnection()
{
System.out.println("Crerate Connection");
connCreated = new Date();
try
{
dbconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1?"+"user=8888888&password=8888888");
dbconn.setAutoCommit(false);
}
catch(Throwable ex)
{
System.out.println("MyError:SQLException has been caught for dbconn close");
ex.printStackTrace(System.out);
}
}
void closeConnection()
{
try
{
if ( dbconn != null )
{
dbconn.close();
}
else
{
//logger.log(Level.SEVERE, "MyError:dbconn is null in finally close", "");
System.out.println("MyError:dbconn is null in finally close");
}
}
catch(SQLException ex)
{
System.out.println("MyError:SQLException has been caught for dbconn close");
ex.printStackTrace(System.out);
}
}