Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem connecting to database

 
shobha devi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ page import="java.sql.*" %>
<%
Connection con;
ResultSet rs;
Statement st;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:oradsn","system","manager");
out.println("Connected ...");
st=con.createStatement();
rs=st.executeQuery( "select * from test");
while(rs.next())
rs.getString(1);
}
catch(Exception ee)
{
out.println("Error While Connecting DataBase" + ee);
}

%>

I cannot connect to database.
oradsn is my dsn name and system,manager are user id and password respectively.
anyone please help me if there is any problem with code so that i can proceed.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The major problem with the code is that it is in a JSP! Move the code out of a JSP and into a Java class where it belongs.

As this is not a JSP question, it has been moved to the JDBC forum.
 
shobha devi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. But if we need to retrieve data from database through Jsp what necessary corrections i need to make.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the JDBC-ODBC bridge? Unless your database is MS Access (in which case you really don't have much choice) you should not be using it. As its docs say, its not really production code.


I cannot connect to database.

JDBC will be throwing an exception. What does that exception say?

(BTW: I have to second what Bear says - code directly in JSPs is not a good thing. Its hard to maintain, and hard to develop).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic