could anyone help me with a proble in connecting a database through struts. Im using tomcat 4.1 and Eclipse IDE. well the IDE is not relevant but ...I have created a connection class in which i Have the following code :
public class MyConnection
public Connection con=null;
public ResultSet rs=null;
public PreparedStatement ps=null;
private DataSource ds=null;
private DataSource GetDataSource()
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/temp");
throw new NamingException("Naming look up Failue first time" + ex.getMessage());
throw new NamingException("Naming look up Failue in initialization." + ex.getMessage());
Now How do i add a <context> code into server.xml. Im connecting to a sybase database. When i careate an object of the above code in a program and call it, it gives the following error :
Error in initializing connection Naming look up Failue first time Cannot create resource instance
I just want to know what code is to be added to the server.xml of tomcat.
following is the driver name and the URL for connectivity
con = DriverManager.getConnection("jdbc:sybase:Tds:192.168.4.8:4100/mtslive","sa","");
pls help as soon as you can,
thanks a lot,
your answer will be a great help to me.
Its good to see you back . I'll put down the info I know related to your question. Check it out if it is of any use. I'm unaware of entries in server.xml as I configured the datasource through Eclipse IDE .I'll put into steps the way I configured my app .
1. In Eclipse, I opened the server configuration and created a datasource in the datasource tab and configured the datasource to my database by specifying all the required info there.
2. Later, I defined a properties file and I read the url and I searched in a context just as you did.
"DataSource ds = ...."
3. For retrieving the connection, I used the "ds" object and retrieved the connection as
"<connection object>=ds.getConnection(<username>,<password>)" and used connection object accordingly.
Give a try in this way.
Remember, Google is out friend
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL