Problem in Creation of two Statement Obj
Hello firends,
i have a problem regarding Creating two Statement obj
its not allowing me to do
<%!
Statement stmt1;
Statement stmt1;
Connection con;
dbcon db;
%>
<%
db=new dbcon(); (its database connection class which m importing)
try
{
con= db.getDbCon();(method of dbcon class)
stmt1=con.createStatement();
stmt2=con.createStatement();
in above two line its giving me error
And when i use
con1= db.getDbCon();(method of dbcon class)
con2= db.getDbCon();(method of dbcon class)
stmt1=con1.createStatement();
stmt2=con2.createStatement();
then its working fine
so i know this is not the proper way to doing thing so how should i solve this problem
plz help me
}catch(SQLException)
{
....
}
# 3
Thanaks for reply but my that problem is solved,i would like to ask u
i have following simple code
<%@ page import="java.sql.*,com.example.model.*" session="true" %>
<%!
ResultSet rs;
Statement stmt;
Connection con;
%>
<%
dbcon cn=new dbcon();
con=cn.connectdb();
try
{
stmt=con.createStatement();
rs=stmt.executeQuery("select mf_id,mf_lr_id,mf_origin,mf_destination from Manifest");
if(rs.next())
{
out.println(rs.getInt("mf_id")+"<br/>");
out.println(rs.getInt("mf_lr_id")+"<br/>");
out.println(rs.getInt("mf_destination")+"<br/>");
out.println(rs.getInt("mf_origin")+"<br/>");
}
}catch(SQLException se)
{
out.println(se);
}finally
{
try
{
if(rs!=null)
{
rs.close();
}
if(stmt!=null)
{
stmt.close();
}
if(con!=null)
{
con.close();
}
}catch(SQLException se1)
{}
}
%>
in this code m just fetching "mf_destination" field before "mf_origin"
thien its giving Error Msg
89
58
14 java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
and suppose i fetch it in sequence as define in select stmt then its working fine.
so this sequence i can maintain in small data but if i use
Select * from ........
then should i fetch all data as its sequence in database Table
# 4
A driver does not have to allow you to access columns "out of order" or multiple times. You should always access each column in a row one time, and from left to right, unless you know your driver supports it. As far as how to be sure that you are doing that when you do select *,
well use getInt(int) rather than getInt(string) using the getColumnCount method of ResultSetMetaData to ensure you don't use too large an int or, use getColumnCount and getColumnName cycling through the column names in the ResultSetMetaData, then you can use getInt(string).