J2EE: insert failure using executeUpdate (w/ ms sqlserver ODBC)
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ruthee_yak
Posted On:   Thursday, August 5, 2004 02:53 PM

Hi, I having trouble with a java/J2EE application that I'm writting. I was wondering if its something you can give me some insight. In my application, I'm able to connection to a sql server database and select records in the database successful. However, when I try to insert data into the database, it fails. At first I thought it was due to syntax errors, but that's not the case. For instance, in my program, if I do a select statement right after the insert, the record I just inserted is return. Somehow the insert is deleted from the database once my application exits. So, I'm wondering if you have some idea on what could be going on. I'm using ODBC to connect to my MS SQLServer database. Do you know of a   More>>


Hi,

I having trouble with a java/J2EE application that I'm writting. I was wondering if its something you can give me some insight.


In my application, I'm able to connection to a sql server database and select records in the database successful. However, when I try to insert data into the database, it fails. At first I thought it was due to syntax errors, but that's not the case. For instance, in my program, if I do a select statement right after the insert, the record I just inserted is return. Somehow the insert is deleted from the database once my application exits.


So, I'm wondering if you have some idea on what could be going on. I'm using ODBC to connect to my MS SQLServer database. Do you know of any insert priviledges that I should be setting either on the J2EE side or SQL Server? I'm clueless at this point...


'preciate your assistance!!,

*Ruth

Here's sample of my code:

			
InitialContext icx = new InitialContext();
DataSource dsn = (DataSource)icx.lookup("java:comp/env/jdbc/javaSQLDB");
con = dsn.getConnection();
String insertSet = null;
try
{
PreparedStatement stmt2 = null;
ResultSet rs = null;
int id = 3;
insertSet = "insert into eMusicWorld..Customer(C_code, C_username, C_password, C_secrtQ, C_secrtAns, C_ccNum, ";
insertSet = insertSet + "C_ccType, C_Fname, C_Lname, C_Addr, C_City, C_State, C_Zip, C_phone)";
insertSet = insertSet + "values(?, ?, ?, ?, ?, ?, ";
insertSet = insertSet + "?, ?, ?, ?, ?, ?, ?, ?)";
System.out.println(insertSet);
stmt = con.prepareStatement(insertSet);
stmt.setInt(1,id);
stmt.setString(2,user);
stmt.setString(3,pswd);
stmt.setString(4,scrtQ);
stmt.setString(5,scrtA);
stmt.setString(6,ccnum);
stmt.setString(7,cctype);
stmt.setString(8,fn);
stmt.setString(9,ln);
stmt.setString(10,addr);
stmt.setString(11,cty);
stmt.setString(12,st);
stmt.setString(13,zip);
stmt.setString(14,phone);
int flag = stmt.executeUpdate();
System.out.println("This is sadd!!! " + flag);
stmt.close();
stmt2 = con.prepareStatement("Select * from eMusicWorld..Customer");
rs = stmt2.executeQuery();
while(rs.next())
{
System.out.print(rs.getString(1));
System.out.print(" " + rs.getString(2)); System.out.println(" " + rs.getString(3));
}
stmt2.close();
}
catch(Exception ex)
{
System.out.println("Ruth...insert error occurred!" + ex);
}

   <<Less
About | Sitemap | Contact