How to connect jsp with javabean for database connection?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jana_r
Posted On:   Friday, December 21, 2001 06:54 PM

I have to use java beans for connecting to database(connection only) and i have to execute my sql queries in JSP. The sample jsp code is given below please tell me how to connect to database for connection only and execute my query statements in JSP. With regards, Jana. <%@ page import="java.sql.* " %> <%! ResultSet rs; String paged="page1" ; %> <% try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:page"); Statement s = con.createStatement(); s.executeUpdate("INSERT IN   More>>


I have to use java beans for connecting to database(connection only) and i have to execute my sql queries in JSP.

The sample jsp code is given below please tell me how to connect to database for connection only and execute my query statements in JSP.


With regards,

Jana.






<%@ page import="java.sql.* " %>

<%! ResultSet rs; String paged="page1" ; %>

<%


try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbc:odbc:page");

Statement s = con.createStatement();

s.executeUpdate("INSERT INTO page (page) " + " VALUES('"+paged+"')");
out.println("exec in sql stat1");
}

catch(Exception e){

System.out.println("exec in sql stat");
}


%>





   <<Less

Re: How to connect jsp with javabean for database connection?

Posted By:   Anonymous  
Posted On:   Tuesday, December 25, 2001 12:57 PM

A common approach to your code would be to place your try-catch block in a static method in a class called fx. DBManager.
This static method could return a boolean on updates, and a collection on selects.
You should execute this method in the top of your jsp/or in a servlet and then use the body of the jsp to present the result in fx. html.
Your jsp's is supposed to contain a minimum of javacode.
About | Sitemap | Contact