Inserting records into an Oracle DB using Java - java

I am getting a missing comma error and I can't seem to figure out what could be causing it, any help would be appreciated.
Table create SQL:
CREATE TABLE APPOINTMENTS (APP_ID NUMBER(38) NOT NULL, I_ID NUMBER(38), DATE_TIME VARCHAR2(50), INSPECTION_TYPE VARCHAR2(30), PRICE VARCHAR2(10), HST VARCHAR2(10), TOTAL VARCHAR2(10), CLIENT_NAME VARCHAR2(40), CLIENT_NUMBER VARCHAR2(15), CLIENT_EXT VARCHAR2(10), CLIENT_EMAIL VARCHAR2(50), CLIENT_NAME2 VARCHAR2(40), CLIENT_NUMBER2 VARCHAR2(15), CLIENT_EXT2 VARCHAR2(10), CLIENT_EMAIL2 VARCHAR2(50), ADDRESS VARCHAR2(100), INTERSECTION VARCHAR2(100), CITY VARCHAR2(40), AGENT_ID NUMBER(38), REF_SOURCE VARCHAR2(30), BUILDING_TYPE VARCHAR2(30), SQUARE_FEET NUMBER(38), LIST_PRICE VARCHAR2(15), LOCKBOX VARCHAR2(40), VACANT VARCHAR2(10), NOTES VARCHAR2(255), BILL_TO VARCHAR2(20), PICTURES_REQUESTED VARCHAR2(10), FLAG VARCHAR2(10), APPROVED VARCHAR2(10), BUILDING_PREMIUM VARCHAR2(10), TRAVEL_PREMIUM VARCHAR2(10), SIZE_PREMIUM VARCHAR2(10), HOLIDAY_PREMIUM VARCHAR2(10), MISC_PREMIUM VARCHAR2(10), INSPECTOR_PAID VARCHAR2(10), COMPANY VARCHAR2(10) NOT NULL, SUGGESTED_RETAIL VARCHAR2(10), SUGGESTED_HST VARCHAR2(10), SUGGESTED_TOTAL VARCHAR2(10), PRIMARY KEY (APP_ID));
Java code to insert and execute:
dc.query = "INSERT INTO HR.APPOINTMENTS (APP_ID,I_ID, DATE_TIME,INSPECTION_TYPE, PRICE, HST, TOTAL, CLIENT_NAME, CLIENT_NUMBER, CLIENT_EXT, CLIENT_EMAIL,CLIENT_NAME2, "
+ "CLIENT_NUMBER2, CLIENT_EXT2, CLIENT_EMAIL2, ADDRESS, INTERSECTION, CITY, AGENT_ID, REF_SOURCE, BUILDING_TYPE, SQUARE_FEET, LIST_PRICE, LOCKBOX, VACANT,"
+ "NOTES, BILL_TO, PICTURES_REQUESTED, FLAG, APPROVED, BUILDING_PREMIUM, TRAVEL_PREMIUM, SIZE_PREMIUM, HOLIDAY_PREMIUM, MISC_PREMIUM, INSPECTOR_PAID,"
+ "COMPANY, SUGGESTED_RETAIL, SUGGESTED_HST, SUGGESTED_TOTAL)"
+ ""
+ "VALUES (" + hNum + "," + inspector + ",'" + date1 + "','" + inspectionType + "','" + price + "','" + hst + "','" + total + "','" + clientName + "','" + clientNumber + "','"
+ clientExt + "','" + clientEmail + "','" + clientName2 + "','" + clientNumber2 + "','" + clientExt2 + "','" + clientEmail2 + "','" + address + "','" + cMIntersection
+ "','" + city + "'," + hNum2 + ",'" + rSource + "','" + bType + "', 1000 ,'" + listPrice + "','" + lockbox + "','" + vacant + "','" + sInformation + "','" + billTo + "','"
+ pRequested + "','" + flagged + "', 'No', 'No', '0' , '0', '0', '0', '0', 'No','" + company + "','" + suggestedPrice + "','" + suggestedhst + "','" + suggestedTotal + "')";
dc.rset = dc.stmt.executeQuery(dc.query);

Here is a more generic approach. You just need to worry about class Oracle below and perhaps add some new entries for Factory method as I only defined a couple for you.
I also coded the actual execute for your PreparedStatement in the Row class, however I never tested that far. Let me know if it works for you (Don't forget to set your database credentials and stuff) ...
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class Oracle {
public static void main(String[] args) {
Row row = new Row("OWNERNAME", "TABLENAME");
row.setDummyValues();
// set your individual column values here as you debug ...
System.out.println( row.getPreparedStatement() );
// for(Column column : row.getColumns()) {
// System.out.println("[" + column.name + "][" + column.type + "][" + column.nullable + "[" + column.value + "]");
// }
}
}
class Column {
int position;
String name;
String type;
boolean nullable;
Object value;
public Column(ResultSet resultSet) throws SQLException {
position = resultSet.getInt("COLUMN_ID");
name= resultSet.getString("COLUMN_NAME");
type= resultSet.getString("DATA_TYPE");
nullable= resultSet.getBoolean("NULLABLE");
value = null;
}
}
class DummyValueFactory {
public static Object createDummyValue(String type, boolean nullable) {
Object value = null;
if(!nullable) {
if(type.contains("CHAR")) {
value = "ABC";
}
else if(type.contains("NUMBER")) {
value = new Integer("123");
}
else if(type.contains("TIMESTAMP")) {
value = new java.sql.Timestamp(System.currentTimeMillis());
}
else {
throw new RuntimeException("CANNOT BUILD A DUMMY VALUE FOR " + type);
}
}
return value;
}
}
class Row {
String owner;
String table;
List<Column> columns = new ArrayList<Column>();
public Row(String ownerName, String tableName) {
owner = ownerName;
table = tableName;
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
connection = getConnection();
statement = connection.createStatement();
resultSet = statement.executeQuery(getMetaDataQuery());
while(resultSet.next()) {
columns.add(new Column(resultSet));
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
if(resultSet != null) {
resultSet.close();
}
if(statement != null) {
statement.close();
}
if(connection != null) {
connection.close();
}
}
catch (SQLException e) {
statement = null;
connection = null;
}
}
}
public void setDummyValues() {
for(Column column: columns) {
column.value = DummyValueFactory.createDummyValue(column.type, column.nullable);
}
}
public List<Column> getColumns() {
return columns;
}
public Column getColumn(String columnName) {
Column foundColumn = null;
for(Column column: columns) {
if(column.name.equals(columnName)) {
foundColumn = column;
break;
}
}
return foundColumn;
}
public boolean setColumn(String columnName, Object value) {
boolean result = false;
for(Column column: columns) {
if(column.name.equals(columnName)) {
column.value = value;
result = true;
break;
}
}
return result;
}
private final String getMetaDataQuery() {
String SQLString = "SELECT COLUMN_ID,\n";
SQLString += " COLUMN_NAME,\n";
SQLString += " DATA_TYPE,\n";
SQLString += " NULLABLE\n";
SQLString += "FROM ALL_TAB_COLUMNS\n";
SQLString += "WHERE OWNER = '" + owner + "'\n";
SQLString += " AND TABLE_NAME = '" + table + "'\n";
SQLString += "ORDER BY COLUMN_ID";
return SQLString;
}
public String getPreparedStatement() {
int counter = 0;
String SQLString = "INSERT INTO " + owner + "." + table + "(\n";
for(Column column : columns) {
if(counter++ > 0) {
SQLString += ", ";
}
SQLString += "\t" + column.name + "\n";
}
SQLString += ") VALUES (\n";
counter = 0;
for(int index = 0; index < columns.size(); index++) {
if(counter++ > 0) {
SQLString += ", ";
}
SQLString += "\t?\n";
}
SQLString += ")";
return SQLString;
}
public void executeInsert() {
Connection connection = null;
PreparedStatement preparedStatement = null;
String SQLString = getPreparedStatement();
try {
connection = getConnection();
preparedStatement = connection.prepareStatement(SQLString);
for(int index = 0; index < columns.size(); index++) {
preparedStatement.setObject(index, columns.get(index).value);
}
preparedStatement.executeUpdate();
}
catch (SQLException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
if(preparedStatement != null) {
preparedStatement.close();
}
if(connection != null) {
connection.close();
}
}
catch (SQLException e) {
preparedStatement = null;
connection = null;
}
}
}
private static final Connection getConnection() throws ClassNotFoundException, SQLException, IOException {
String user = "username";
String password = "password";
String server = "server";
int port = 1234;
String sid = "database";
Connection connection = null;
String url = "jdbc:oracle:thin:#" + server + ":" + port + ":" + sid;
Class.forName("oracle.jdbc.driver.OracleDriver");
java.util.Properties info = new java.util.Properties();
info.put ("user", user);
info.put ("password", password);
info.put ("useFetchSizeWithLongColumn", "true");
connection = DriverManager.getConnection(url, info);
return connection;
}
}

Related

How to print out a specific column from MySQL in java

I am trying to print out all the columns that has the same path as the one that i get from an Image. The main problem is that path='path' is read as a string with the value "path" instead of the value that i have in my path-variable. path = path without the '' is not accepted as a value, and therefore i can't print the columns. if i directly insert path='C:\Users....\' here, it prints out the right columns.
public void getImageInfoFromDatabase(Image image) {
String path = image.getFile().getAbsolutePath();
path = path.replace("\\", "\\\\");
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connect = DriverManager.getConnection(url, user, pass);
Statement statement = connect.createStatement();
resultSet = statement.executeQuery("SELECT * FROM image_table WHERE path='path'");
while (resultSet.next()) {
int id = resultSet.getInt(1);
String title = resultSet.getString(2);
String path = resultSet.getString(3);
String tags = resultSet.getString(4);
String latitude = resultSet.getString(5);
String longitude = resultSet.getString(6);
java.util.Date timestamp = resultSet.getTimestamp(7);
System.out.println(id + " " + title + " " + path + " " + tags + " " + latitude + " " + longitude + " " + timestamp);
}
} catch (SQLException | ClassNotFoundException e) {
System.out.println("Error. ");
e.printStackTrace();
}
}
I found out that i had to use the setString method from PreparedStatement to input a value at a specific index. The complete functioning code looks like this:
public boolean getImageInfoFromDatabase(Image image) {
boolean success = true;
String string = image.getFile().getAbsolutePath();
string = string.replace("\\", "\\\\");
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connect = DriverManager.getConnection(url, user, pass);
PreparedStatement stmt = connect.prepareStatement("SELECT * FROM image_table WHERE path = ?");
stmt.setString(1, string);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
int id = resultSet.getInt(1);
String title = resultSet.getString(2);
String path = resultSet.getString(3);
String tags = resultSet.getString(4);
String latitude = resultSet.getString(5);
String longitude = resultSet.getString(6);
java.util.Date timestamp = resultSet.getTimestamp(7);
System.out.println(id + " " + title + " " + path + " " + tags + " " + latitude + " " + longitude + " " + timestamp);
success = true;
}
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
success = false;
}
return success;
}
SELECT * FROM image_table WHERE path='path'

how to insert data in my sql using else if in jsp

Hi I'm trying to insert data in mysql but my page throw no response!
pease can anyone help me about it?
Code runs but println() is not displaying
//<%#page import= "java.sql.*"%>
// <%# page import="java.util.Random"%>
<%
String dt = request.getParameter("dt");
String particular = request.getParameter("vas");
String emp = request.getParameter("emp");
String amt = request.getParameter("amt");
int amnt = Integer.parseInt(amt);
//Class.forName("com.mysql.jdbc.Driver");
//Connection con = //DriverManager.getConnection("jdbc:mysql://localhost:3306/furqania", "root", "khan");
Statement st = con.createStatement();
if (particular == "amanatraseedi")
{
Random rnd = new Random();
int rn = rnd.nextInt(9000) + 10000;
String sr = "AMT" + rn;
// int i = st.executeUpdate("insert into amanatraseedi='"+particular+"'(transactionid,dt,amount,empid) values('" + sr + "','" + dt + "','" + amnt + "','" + emp + "')");
if (i > 0) {
out.println("Amanat raseedi successful!");
} else {
out.println("something went wrong!");
}
}
else if (particular == "amadhisab")
{
Random rnd = new Random();
int rn = rnd.nextInt(9000) + 10000;
String sr = "AMD" + rn;
int i = st.executeUpdate("insert into amadhisab='"+particular+"' (transactionid,dt,amount,empid) values('" + sr + "','" + dt + "','" + amnt + "','" + emp + "')");
if (i > 0) {
out.println("Amad hisab successful!");
}
else {
out.println("something went wrong!");
}
}
st.close();
con.close();
%>

Java SQLException on a string that runs in mysql

I am trying to make an inserction of a cliente.
When I print the string from the executeUpdate, copy and paste on mysql, the data is inserted with no problem.
The Exception has the follow description:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update cliente set honorarioMensal = 2000.2 where cnpj = 'cnpj_ex'' at line 2
Can somebody help me?
public class Teste {
public static void main(String[] args) throws SQLException {
try {
Industria industria = IndustriaDB.getById(1);
System.out.println(industria);
Funcionario funcionario = new Funcionario("Func1","Func1");
funcionario.setCustoMensal(22);
Cliente cliente = new Cliente("cnpj_ex", "nome_ex",industria);
cliente.setPreco((float) 2000.2);
System.out.println(cliente);
System.out.println(cliente.getFuncionario());
ClienteDB.inserir(cliente);
ClienteDB.deletar(cliente);
} catch (ContexataException ge) {
System.out.println("---> " + ge.getMessage());
System.out.println("---> Detalhamento do erro: ");
ge.printStackTrace();
} finally {
}
}
}
public class ClienteDB extends Conexao{
public static void inserir(Cliente cliente) throws ContexataException, SQLException, NullPointerException {
Connection conn = Conexao.getConnection();
try {
String createString =
"INSERT into cliente "
+ "(cnpj, nome, id_Industria) "
+ "values('" + cliente.getCnpj() + "','"
+ cliente.getNome() + "',"
+ cliente.getIndustria().getId() + ");";
if (cliente.getFuncionario() != null){
createString = createString + "\n update cliente set cpf_Funcionario = '" + cliente.getFuncionario().getCpf() + "' where cnpj = '" + cliente.getCnpj() + "';";
}
if (cliente.getPreco() != 0.0){
createString = createString + "\n update cliente set honorarioMensal = " + cliente.getPreco() + " where cnpj = '" + cliente.getCnpj() + "';";
}
System.out.println("SQL: " + createString);
executeUpdate(conn, createString);
System.out.println("Novo cliente inserido!\n");
// } catch (SQLException e) {
// throw new ContexataException("Erro ao inserir novo cliente.");
} catch (NullPointerException e) {
throw new ContexataException("Alguns dados não foram preenchidos suficientemente para o banco de dados!");
} finally {
Conexao.closeAll(conn);
}
}
public class Cliente { // only the atributes are necessary...
private String cnpj;
private String nome;
private float preco;
private Industria industria;
private Funcionario funcionario;
// getter and setter...
The problem is \n characters in the query string. You shouldn't use them, check your code and remove invalid characters.
if (cliente.getFuncionario() != null){
createString = createString + " update cliente set cpf_Funcionario = '" + cliente.getFuncionario().getCpf() + "' where cnpj = '" + cliente.getCnpj() + "';";
}
if (cliente.getPreco() != 0.0){
createString = createString + " update cliente set honorarioMensal = " + cliente.getPreco() + " where cnpj = '" + cliente.getCnpj() + "';";
}
And you can't writeupdate in the insert statements.
You cannot think about your problem like if you were typing the commands in a GUI. You must execute one executeUptade per statement rather than a batch of them. Of course also remove the ; at the end of the statement.
In fact GUIs probably will split your sql sentences and then send them one by one to SQL one by one.

SQLite java.lang.NullPointerException in only select query

i added sqlite-jdbc-3.7.2.jar to build path. I used insert query. when i opened the wellec.db with notepad, i can see records. But my select is not working.
HERE WellInfo class properties
public Integer wellID;
public Integer measurement;
public String wellname;
public Integer wellstatus;
public String licenseno;
public String gl;
public String kb;
public String spuddate;
public String drillingenddate;
public String totaldepth;
public String notes;
public String easting;
public String northing;
public String coordinatesystem;
public Integer islogadd;
here is my createtable sql
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:wellec.db");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "CREATE TABLE IF NOT EXISTS WELLINFO " +
"(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ," +
" WELLNAME CHAR(90) NOT NULL, " +
" WELLSTATUS INT NOT NULL," +
" MEASUREMENT INT NOT NULL," +
" ISLOGADD INT NOT NULL," +
" GL CHAR(50) NOT NULL, " +
" KB CHAR(50) NOT NULL, " +
" SPUDDATE CHAR(50) NOT NULL, " +
" TOTALDEPTH CHAR(50) NOT NULL, " +
" LICENSENO CHAR(50) NOT NULL, " +
" DRILLINGENDDATE CHAR(50) NOT NULL, " +
" NOTES CHAR(150) NOT NULL, " +
" EASTING CHAR(50) NOT NULL, " +
" NORTHING CHAR(50) NOT NULL, " +
" COORDINATESYSTEM CHAR(50) NOT NULL)";
stmt.executeUpdate(sql);
...//other tables sql and stmt.executeUpdate(sql)
stmt.close();
c.commit();
here is my insert query which is working. WellInfo wi as parameter
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:wellec.db");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "INSERT INTO WELLINFO " +
"(ID, WELLNAME, WELLSTATUS , MEASUREMENT, ISLOGADD , GL, KB, SPUDDATE, TOTALDEPTH, " +
"LICENSENO , DRILLINGENDDATE, NOTES, EASTING, NORTHING, COORDINATESYSTEM) " +
"VALUES (NULL,'" + wi.wellname + "'," + wi.wellstatus + "," + wi.measurement + "," +
"" + wi.islogadd +",'" + wi.gl + "','" + wi.kb + "','" + wi.spuddate + "'," +
"'" + wi.totaldepth + "','" + wi.licenseno + "','" + wi.drillingenddate + "', " +
"'" + wi.notes + "','" + wi.easting + "','" + wi.northing + "','" + wi.coordinatesystem + "');";
stmt.executeUpdate(sql);
stmt.close();
c.commit();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Records created successfully");
return 0;
here is my select
Connection c = null;
Statement stmt = null;
WellInfo[] wi = new WellInfo[60000];
WellInfo[] wi2 = new WellInfo[0];
int i = 0;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:wellec.db");
//c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("select * from WELLINFO");
//c.commit();
//if(rs.getRow() > 0)
while ( rs.next() ) { //HERE IS THE PROBLEM
wi[i].wellID = rs.getInt("ID");
i++;
}
wi2 = new WellInfo[i];
for(int j = 0; j < i - 1; j++){
wi2[j] = wi[j];
}
rs.close();
stmt.close();
return wi2;
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Operation done successfully");
return wi2;
Sorry not specify the problem. Here it is:
SELECT QUERY problem when i call rs.next(), i got the error java.lang.NullPointerException.
wi[i] is null => you can't call wi[i].wellID before you instantiate wi[i], you should do something like
wi[i] = new WellInfo() then call wi[i].wellID

java database function removed - still executing

I have a java web application that I removed a function from the code and yet the database entries that this function writes are still being written to the database.
Inside the IssueWarrant function there is a call to insertWarrantFee that has been commented out.
private void issueWarrant(String CasePrefix, String CaseNumber, String HearingType, String Suspend)
{
int i = 0, intDivision = 0, pos = 0;
String SummSeq = getSummSeq(CasePrefix, CaseNumber);
String Charges = getCharges(CasePrefix, CaseNumber, HearingType);
boolean isVacated = false, isHearingFound = false;
NextBWNumber warrNbr = new NextBWNumber();
String WarrantNumber = warrNbr.getNextBWNumber();
String warrStatus = warrNbr.getNextBWNStatus();
String HearingDesc = "", Division = "";
isVacated = getVacatedStatus(CasePrefix, CaseNumber, HearingType);
isHearingFound = getHearingStatus (CasePrefix, CaseNumber, HearingType);
HearingDesc = getFormatToday() + " " + getHearingDesc(HearingType);
if (HearingDesc.length() > 30)
{
HearingDesc = HearingDesc.substring(0,30);
}
Division = getHearingJudge(CasePrefix,CaseNumber,HearingType);
intDivision = Integer.parseInt(Division);
if (intDivision < 10)
{ Division = "0" + Division; }
Statement localstmt = null;
String localqueryString;
localqueryString = "INSERT INTO " + library7 + "CMPBWPND" +
" (CASPRE, CASNUM, DEFSEQ, CHGSEQ, SUMSEQ, STSCOD, STSDAT," +
" STATUT, CHGABV, BWNBR, JUDCOD, PRVFLG, CT2FLG, DIVISN, BNDAMT," +
" BTYPE, CMNT, CUSER, TUSER, LUPDAT, SCRDAT, STATSDAT, SUMCRDAT, LUPDATE )" +
" VALUES ('" + CasePrefix + "', " + CaseNumber + ", 1, " + Charges.substring(i, i + 1) +
", " + SummSeq + ", 9, " + getShortDate() + ", 'RCP 12-A TA', 'WARRANT', '" +
WarrantNumber + "', " + intDivision + ", 'N', 1, '" + Division + "', " +
BondAmt + ", '" + BondType + "', '" + HearingDesc + "', 'TAAD', 'TAAD', " +
getShortDate() + ", " + getShortDate() + ", " + getLongDate() + ", " + getLongDate() +
", " + getLongDate() + ")";
try
{
if (!isVacated && isHearingFound)
{
localstmt = conn.createStatement();
localstmt.executeUpdate(localqueryString);
localstmt.close();
StatusMsg = "Client No Show-WI";
}
if (isVacated)
{
StatusMsg = "Client Vacated Case";
}
if (!isHearingFound)
{
StatusMsg = "Client Hearing Missing";
}
} catch (SQLException e)
{
System.out.println("IssueWarr - Error in IssueWarrant");
e.printStackTrace();
ReturnInfo = "Issuing Warrants Failed.";
success = false;
}finally
{
try
{
if (!localstmt.isClosed())
{
localstmt.close();
}
} catch (SQLException sql2)
{
System.out.println("Error trying to close connections. Exception: " + sql2.getMessage());
}
}
**//insertWarrantFee(CasePrefix, CaseNumber, SummSeq, WarrantNumber);**
updateHearingRecord(CasePrefix, CaseNumber, HearingType, Charges.substring(i, i + 1), Suspend);
for ( i = 1; i < Charges.length(); i++ )
{
insertBWPTFRecord(CasePrefix, CaseNumber, SummSeq, Charges.substring(i, i + 1));
}
if (!success)
{
StatusMsg = "Client Iss. Warrant Failure";
}
}
Here is the code that the insertWarrantFee called before it was commented out:
private void insertWarrantFee(String CasePrefix, String CaseNumber, String SummSeq, String WarrantNumber)
{
Statement localstmt = null;
String localqueryString;
ResultSet localrSet = null;
String feeAmt = null;
localqueryString = "SELECT AUTO$$ FROM " + library3 + "CMPDKTTP WHERE DKTTYP = 'W'";
try
{
localstmt = conn.createStatement();
localrSet = localstmt.executeQuery(localqueryString);
while (localrSet.next())
{
feeAmt = localrSet.getString("AUTO$$");
}
localstmt.close();
localrSet.close();
} catch (SQLException e)
{
System.out.println("IssueWarr - Error in Insert Warrant Fee SQL1");
e.printStackTrace();
ReturnInfo = "Issuing Warrants Failed.";
success = false;
}finally
{
try
{
if (!localstmt.isClosed())
{
localstmt.close();
}
} catch (SQLException sql2)
{
System.out.println("Error trying to close connections. Exception: " + sql2.getMessage());
}
}
localqueryString = "INSERT INTO " + library7 + "CMPBWTRN"
+ " (CASPRE, CASNUM, DEFSEQ, SUMSEQ, BWNBR, FEEAMT, DKTTYP, TUSER, LUPDAT)"
+ " VALUES ('" + CasePrefix + "', " + CaseNumber + ", 1, " + SummSeq + ", '" + WarrantNumber
+ "', " + feeAmt + ", 'W', 'TAAD', " + getShortDate() + ")";
try
{
localstmt = conn.createStatement();
localstmt.executeUpdate(localqueryString);
localstmt.close();
} catch (SQLException e)
{
System.out.println("IssueWarr - Insert Warrant Fee SQL2");
e.printStackTrace();
ReturnInfo = "Issuing Warrants Failed.";
success = false;
}finally
{
try
{
if (!localstmt.isClosed())
{
localstmt.close();
}
} catch (SQLException sql2)
{
System.out.println("Error trying to close connections. Exception: " + sql2.getMessage());
}
}
}
So even though the line that called insertWarrantFee is commented out a record is still being inserted into CMPBWTRN.
Any ideas how this could happen? The developer is indicating it could be a tomcat connection cache issue? Any other suggestion beside magical code?
Thanks!
Leslie
A couple of things to try:
Make sure you've redeployed the application and have restarted Tomcat. Check the timestamp of the deployed class in question.
Clean Tomcat's tmp and work directories
Open the deployed Java class using a decompiler to see whether the removed code is still in there.
Add a logging (or System.out.println) statement to the method that's commented out, and to the method calling it. See whether one or both are printed after redeploying the changes.

Categories

Resources