• Post Reply Bookmark Topic Watch Topic
  • New Topic

configuring tomcat to use MsAcess

 
reeti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i m trying one jsp to connect to Ms Acess data base.
when i use same dsn n db in java file i get the output but with
jsp i get an error drivers not found...etc

i read somewhere that in server.xml we have to ad d tag <context.....

to connect jsp to database

can any one tell how to set that tag...



<html>
<head>
<title>
PHI Employees Time Record
</title>
</head>
<font color=#DB1260>

</font>


<h2> PHI EMPLOYEE ASSIGNMENT RECORD</h2>
<body bgcolor=="#Fc99FF">
<font color=#DB1260>

</font>

<%@ page language="java" import="java.sql.* " %>
<%
Connection conn=null ;
String StNo,StFName,StLName;
ResultSet rs=null;
Statement Stmt;



try {


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn= DriverManager.getConnection("jdbcdbc:Empdb","","");

Stmt=conn.createStatement();
rs=Stmt.executeQuery("Select EmpID,Name,IsAssignee FROM Emp");


}


catch (SQLException sqle) {
out.print("Sorry, the database is not available.");
out.print("Exception: " + sqle);

//out.print("SQLException: " + sqle.getMessage());
//out.print("SQLState: " + sqle.getSQLState());
//out.print("VendorError: " + sqle.getErrorCode());
}



try
{


while(rs.next())

{

StNo=rs.getString(1);
StFName=rs.getString(2);
StLName=rs.getString(3);
System.out.println(StNo+" "+StFName+" "+StLName);
}
}

catch (Exception e) {
out.print("Exception occured: " + e);
}

%>


thnx in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
reeti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where to put JDBc Driver?

i read somewhere that i've to add <context>in server.xml

<Context path="/phijdbc1" docbase="" debug="0">
<Resource name="jspjdbc" auth="Container" type="sun.jdbc.odbc.JdbcOdbcDriver"/>
<ResourceParams name="jspjdbc>
<parameter>
<name>username</name>
<value></value>
</parameter>

<parameter>
<name>password</name>
<value></value>
</parameter>


<parameter>
<name>driverClassName</name>
<value>sun.jdbc.odbc.JdbcOdbcDriver</value>
</parameter>

<parameter>
<name>url</name>
<value>jdbcdbc:Empdb</value>
</parameter>

</ResourceParams>
</Context>


is it correct?

regards
reeti
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This kind of connect to database can work with no entry in web.xml. You are connecting to the Access DB directly from the code and this should work. If you can post the Exception trace, we could help you more.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"reeti" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy. User names cannot be obviously fake and must constist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"reeti",

You had already been warned about your display name here.

This is not a suggestion. Change your display name to conform to JavaRanch standards prior to your next post.

bear
Forum bartender.
 
venkat raghavan .R
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try creating a dsn in System dsn
try this piece of code

Class c = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc dbc:stu";
Connection con = DriverManager.getConnection(url);
Statement st= con.createStatement();


create stu dsn in System dsn....i think it should work
stu is dsn name.....if u want i can send a jsp file with the implementation
 
reeti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx Venkat

i created system DSN named Empdb ,i m strucked up in this problem since 15 days if u can really send me the example with implementation i shall really be thankful to u.....n pls make it clear do i need to set context in server.xml n how to do it

thanx
 
venkat raghavan .R
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi reeti,
i dont think u need to create an entry in web.xml file in case of jsp.....but in case of servlets u have to do it.....

number.jsp
----------

<html>
<body>
<h1><u><font color="lightgreen"><b><big><center>Students Information System</center></big></b></font></h1></u>

<form method=post action="details.jsp">

<b><br><br><center>Enter Your Number<input type="text" name="rollno"><br><br>
<input type="submit" name="abc" value="submit" ></input>
</form>
</body>
</html>


details.jsp
-----------
<html>
<body>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.lang.*" %>
<h1><u><font color="lightgreen"><b><big><center>Students Information System</center></big></b></font></h1></u>


<%
String no =request.getParameter("rollno");
int i=0;
try

{

Class c = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc dbc:stu";
Connection con = DriverManager.getConnection(url);
Statement st= con.createStatement();


ResultSet rs = st.executeQuery("select * from stud where RollNo='"+no+"' ");
while(rs.next())
{ i=i+1;
%>

<br><br><br><br><b><center><h2>Student Name :<%out.println(rs.getString(3));%></center></b><br>
<b><center><h2>Roll Number :<%out.println(rs.getInt(2));%></center></b><br>
<b><center><h2>Degree :<%out.println(rs.getString(4));%></center></b><br>
<b><center><h2> Percentage :<%out.println(rs.getInt(5));%></center></b><br>

<%
}
if(i==0)
{
%>

<br><br><BIG><b><center><h1><font color="red">INVALID NUMBER</center></b></big></font><br>

<%
}


}catch(Exception e){out.println(e.getMessage());}

%>

create a database and start the execution with number.jsp once u click submit it will get forwarded to details.jsp where the info. will be retrieved from database and displayed


bye
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"reeti",

This is your final warning. Please change your display name as outlined in previous posts.

bear
Forum bartender
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!