Insert into SQL Server not working.
843836Oct 2 2003 — edited Oct 3 2003Hi,
I am trying to insert data into my sql server database. I tested the code on my laptop which has SQL Server, Tomcat, and my JSP's on it and everything worked great. I was able to insert all kinds of data;-)
BUT, when I installed sql server on the machine that is 8 feet away from me my INSERTS don't work. I don't get any error and everything compiles fine.....it just doesn't show up in the database. Strange huh? Well I was thinking it was a permissions problem so I jumped on Query Analyzer and copied and pasted the exact same code that is in my JSP and the INSERT worked. So this is not a permissions problem. I have posted my code below. Is there some piece of code that I am missing that is needed in my code to process INSERTS over the network?
----------------------------------------------------------------------
<%@ page import="java.sql.*" %>
<%@ page errorPage="error.jsp" %>
<%
String Name = request.getParameter("Name");
String UserName = request.getParameter("UserName");
String Pass = request.getParameter("Pass");
String CompName = request.getParameter("CompName");
String Cust_Id = " ";
String Eusername = " ";
String sql2 = " ";
%>
<HTML>
<HEAD><TITLE>User Process</TITLE></HEAD>
<BODY bgcolor="#990033">
<font color = "#000000">
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://FLOATERPC01:1433;DatabaseName=Returns","test","test");
java.sql.Statement Estmt = conn.createStatement();
java.sql.ResultSet Ers = Estmt.executeQuery("SELECT distinct Login from LOGIN where Login = '"+ UserName +"'");
while (Ers.next()){
Eusername = Ers.getString("Login");
}
Ers.close();
Estmt.close();
if (UserName.equals(Eusername)){
conn.close();%>
<jsp:forward page="taken.jsp"/>
<%}%>
<%
java.sql.Statement stmt = conn.createStatement();
java.sql.ResultSet rs = stmt.executeQuery("SELECT distinct CUST_ID, CUST_NAME From Company where CUST_NAME = '"+ CompName +"'");
while (rs.next()){
Cust_Id = rs.getString("CUST_ID");
}
java.sql.Statement updStmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
int uppdRS = updStmt.executeUpdate("INSERT INTO CUSTOMER (CUST_ID, Customer_Name, Login, Password) values ('"+ Cust_Id +"', '"+ Name +"', '"+ UserName +"', '"+ Pass +"')");
stmt.close();
updStmt.close();
conn.close();
if (uppdRS != 0)
{
application.setAttribute("Name", Name);
application.setAttribute("CompName", CompName);
application.setAttribute("Cust_Id", Cust_Id);
application.setAttribute("UserName", UserName);
%>
<jsp:forward page="beenadded.jsp"/>
<%
}
%>
</font>
</BODY>
</HTML>