dcsimg
How to run this application in JSP....
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tomislav_Tuzlak
Posted On:   Thursday, September 5, 2002 01:17 AM

I have this code and I would like to run it in JSP, but all I get is a blank page... import java.sql.*; import java.math.*; public class connectDB { public static void main(String args[]) { String userName="Username"; String password="Pswd"; String url = "jdbc:odbc:ODBC"; String query = "SELECT FirstName, SecondName FROM Staff"; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (ClassNotFoundException e) { System.err.print("ClassNotFoundException: " + e); } try { Connection con = DriverMa   More>>

I have this code and I would like to run it in JSP, but all I get is a blank page...

			
import java.sql.*;
import java.math.*;

public class connectDB
{

public static void main(String args[])
{

String userName="Username";
String password="Pswd";
String url = "jdbc:odbc:ODBC";
String query = "SELECT FirstName, SecondName FROM Staff";

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: " + e);
}

try
{
Connection con = DriverManager.getConnection(url, userName, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

System.out.println("Customer Names and Email Address:");
while (rs.next())
{
String name = rs.getString("FirstName");
String emailaddress = rs.getString("SecondName");
System.out.println(" " + name + " " + emailaddress);
}

stmt.close();
con.close();
}
catch(SQLException e)
{
System.err.println("SQLException: " + e);
}
}
}
   <<Less

Re: How to run this application in JSP....

Posted By:   Thomas_Hackel  
Posted On:   Thursday, September 5, 2002 02:17 AM

first read about JSP and servlets !!!
just insert the CODE only into the JSP not the package,import,class,method stuff... and DON't use System.out.println (nothing will be visible at the page, only in the console where the servlet-engine was started or in the log files of the engine). get the PrintWriter from HttpServletRequest or do the output in the JSP via HTML... but please read something to JSP&Servlets before.
About | Sitemap | Contact