Total members 11894 |It is currently Fri Nov 22, 2024 1:23 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





I created a database in derby (with ij tool). I wanted to connect
this database through JSP page from Tomcat 6 server.

I started the Network Server from Command Window(Server Shell)

Server started (used 1527 port)

I connected the created database by typing:

ij> connect 'jdbc:derby://localhost:1527/assetsdb;create=true';

Can I access the database from JSP page this way?
//Sign.jsp

Code:
<html>
<head>
<title>Sign Up</title>
</head>
<body>
<%@ page language="java" import="java.sql.*" %>
<%
Connection conn;
conn=null;
ResultSet rs;
rs=null;
String empID=request.getParameter("empID");
String pwd1=request.getParameter("pwd1");
String pwd2=request.getParameter("pwd2");

int flag=0;

String driver="org.apache.derby.jdbc.ClientDriver";
String dbName="assetsdb";
String
connURL="jdbc:derby://localhost:1527/"+dbName+";create=true";
String selQuery="SELECT * FROM Employees where ID=?";
String inQuery="INSERT INTO Viewers values(?,?)";
try
{
Class.forName(driver);
conn=DriverManager.getConnection(connURL);
PreparedStatement stat=conn.prepareStatement
(selQuery);
stat.setString(1,empID);
rs=stat.executeQuery();
if(!rs.next())
{
flag=1;
%>
<script type="text/javascript">
alert("Employee ID Not Found.");
location.href="NewViewer.htm";
</script>
<%
conn.close();
}
}
catch(Exception e)
{
out.println("Mistake:"+e);
}
if(flag==0)
{
try
{
Class.forName(driver);
conn=DriverManager.getConnection(connURL);
PreparedStatement stat1=conn.prepareStatement
(inQuery);
stat1.setString(1,empID);
stat1.setString(2,pwd1);
stat1.executeUpdate();
flag=0;
response.sendRedirect("login.htm");
}
catch(Exception e)
{
out.println("Mistake inserting values:"+e);
}
finally
{
rs.close();
conn.close();
}
}
%>
</body>
</html>
------------
Where am I wrong in connecting to the database? I placed the
Sign.jsp page in Tomcat's ROOT/JSPs/Sign.jsp and the database in
E:\IT Assets\assetsdb




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

URL should be like this jdbc:derby://localhost:1527/vir
i think u have not provided username and password
Connection string is "URL","<username>",<password>


Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Unable to connect to JavaDB Database
 How to connect database with Applets     -  
 How do I connect my form tomy database     -  
 How do I connect my form tomy database     -  
 Connect to database Microsoft access within jsp servlet     -  
 How to connect two computers and connect them with Internet?     -  
 Unable to open OST file in C# [.net]     -  
 Unable to find javax.servlet     -  
 Connect Dots     -  
 connect to MYSQL from ASP     -  
 how to connect applet with excel     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com