how to update many tables using the same code

<%@ page language ="java"import ="java.sql.*" %>

<%@ pageimport ="java.sql.*" %>

<%@ pageimport ="java.text.*" %>

<%

String custname1=request.getParameter("custname");

session.setAttribute("custname",custname1);

String custtin1=request.getParameter("custtin");

session.setAttribute("custtin",custtin1);

%>

<%

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection conn;

conn=DriverManager.getConnection("jdbc:odbc:loginval");

Statement stat=conn.createStatement();

String stmt="insert into custdetails values('"+custname1+"','"+custtin1+"')";

stat.executeUpdate(stmt);

stat.close();

conn.close();

%>

<jsp:forward page ="success.html"/>

<%

}

catch(Exception e)

{

%>

<jsp:forward page ="tinerror.jsp"/>

<%

}

%>

this is my code, now this code will be used by many users to update their corresponding tables. so my problem is based on the username i need to change the table name in the insert query, for example if the username is sai, then the table name has to be saicustdetails and if the user name is ram then the table name in the query has to be ramcustdetails. and so on.

please help

[2000 byte] By [kiranmea] at [2007-11-26 20:35:04]
# 1
Kiran get the user byString User = request.getParameter("username");if(User!=null && User!="")User=User+"custdetails";Now you can fire the query as "insert into "+User+" values('"+custname1+"','"+custtin1+"')";OK
Ankia at 2007-7-10 1:27:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

*<%@ page language = "java" import = "java.sql.*" %>

<%@ page import = "java.sql.*" %>

<%@ page import = "java.text.*" %>

<%

String tin1=request.getParameter("tin");

session.setAttribute("tin",tin1);

tin1=tin1+"custdetails";

String custname1=request.getParameter("custname");

session.setAttribute("custname",custname1);

String custtin1=request.getParameter("custtin");

session.setAttribute("custtin",custtin1);

//String tin2;

%>

<%

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection conn;

conn=DriverManager.getConnection("jdbc:odbc:loginval");

Statement stat=conn.createStatement();

String tin2;

tin2=tin1;

String stmt="insert into "+tin2+"values('"+custname1+"','"+custtin1+"')";

stat.executeUpdate(stmt);

stat.close();

conn.close();

%>

<jsp:forward page = "success.html"/>

<%

}

catch(Exception e)

{

%>

<jsp:forward page = "tinerror.jsp"/>

<%

}

%>

i tried what u have said but still it does not work, anyother way?

kiranmea at 2007-7-10 1:27:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
thanks anki its working
kiranmea at 2007-7-10 1:27:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...