Common connection in JSP

Common connection in JSP

View Answers

June 12, 2009 at 5:27 PM

Hi Friend,

We are providing you the code where we have used database Connection object into another jsp page to retrieve the column names of the specified table.

1)Create connection.jsp

<%@ page import="java.sql.*,java.io.*" %>
<html>
<head>
<title>Getting Column Names using Metadata</title>
</head>
<body>
<h2>Column Names of table "Country"</h2>
<%
Connection con=null;
ResultSet rs=null;
Statement stmt=null;
ResultSetMetaData md;
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://192.168.10.211/mysql?user=root&password=root";;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage());
}
%>
2)Create include.jsp
<%@ page import="java.sql.*,java.io.*" %>
<%@include file="connection.jsp" %>

<%try{
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM country");
md = rs.getMetaData();
int count = md.getColumnCount();
out.println("<table border=1>");
out.print("<tr>");
for (int i=1; i<=count; i++) {
out.print("<th>");
out.print(md.getColumnName(i));
}
out.println("</tr>");
out.println("</table>");
}
catch (SQLException ex) {}
%>
</body>
</html>
Thanks









Related Tutorials/Questions & Answers:
Common connection in JSP - JSP-Servlet
Common connection in JSP  Hi I am creating an JSP application. I want to use a common JSP page so that I can include it into other pages and get connection to database. I am able to get connection in other(common) JSP
JSP- common dbase connection - JSP-Servlet
JSP- common dbase connection  Hi! Thanks for your suggession... connection.... I want to write only one dbase connection and i want to call that connection through out project wherever I want to connect... I dont want to use Beans
Advertisements
Dbase connection - JSP-Servlet
Dbase connection  Hi! how to write common dbase connection for all JSP pages. In how many ways we can write this... send me any code if u have.......... Thanks in advance
connection of jsp with mysql - JSP-Servlet
Example of connection between JSP and MYSQL  Need an example of connection between JSP and MYSQL
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
connection of jsp with mysql - JSP-Servlet
connection of jsp with mysql  can anybody tell me about connection of JSP with MYSQL? and also tell me which version is compatible with tomcat 4.1 i am using tomcat 4.1, MYSQL 5.0 but i have problem with connection
connection to mysql in jsp
connection to mysql in jsp  please i got this error message when trying to connect to mysql database in jsp. Unknown character set: 'utf8mb4
jsp connection to db2
jsp connection to db2  hello friends i have a project to do in jsp using db2 database can anyone please help me in connecting a jsp page to db2 database?? please frienda help me
Connection Pooling - JSP-Servlet
Connection Pooling  Hi All, Iam new to Connection Pooling in Java. I need to create connection pooling for my MySQL Database with JSP using Bean... Connection con=null; public static Connection getConnection() { try
connection with database - JSP-Servlet
and the connection with the database using jsp code, I get exceptions that I have... with java code. Is there any other way to establish a connection with database in jsp...connection with database  I tried the DSN and connection
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
JSP - MySQL - Connection
JSP - MySQL - Connection  I can't connect mysql using jsp in my server.It shows some error like this. """ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received
Use of Connection Pooling - JSP-Servlet
Use of Connection Pooling  Dear Friends i want to use connection pooling in my jsp page i created one connectionPooling.java is : package... Connection con=null; public static Connection getConnection() { try
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
server database connection - JSP-Servlet
ODBC For Oracle}","scott","tiger"); But how to get the connection from..." in that case how we will get the database connection   Hi Friend
connection with mysql with jstl - JSP-Servlet
connection with mysql with jstl  hi, i m working on jstl . i hv done connection in MS -Access with JSTL . The code is working well. but when i am trying to connect database with mysql 5.0 it is creating problem. Plz tell me
How to design https connection page using JSP
How to design https connection page using JSP  Hi, I have a project in which a page requires https secure design to process the payment. Since... JSP Thank you
jsp to cassandra datbase connection by using eclipse
jsp to cassandra datbase connection by using eclipse  sir i want to connect the apache cassandra datbase by using cql query language. i am success by using simple java application.now my task is to interact with cassandra
code for jsp to db connection using jdbc
code for jsp to db connection using jdbc  please send me the code...;html> <form method="post" action="http://localhost:8080/examples/jsp...("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con
Java Thread not geting Connection pool - JSP-Servlet
Java Thread not geting Connection pool  Hi All, Please help me in following problem. I have database connection on server using connection pool... while getting database connection in Background process. I am passing
how to connection jsp to oracle database connections in netbeans ide
how to connection jsp to oracle database connections in netbeans ide  how to connect jsp to oracle database connections in netbeans ide?pls provide screenshots if possible
how to connection jsp to oracle database connections in netbeans ide
how to connection jsp to oracle database connections in netbeans ide  how to connect jsp to oracle database connections in netbeans ide?pls provide screenshots if possible
java multiple users with single connection - JSP-Servlet
it for multiple users who uses a single connection to the database simultaneously... of the above websites uses a single connection with multiple users. n...{ Class.forName("com.mysql.jdbc.Driver"); Connection con
how to auto generate number in jsp with the database connection mysql for employee number?
how to auto generate number in jsp with the database connection mysql for employee number?  how to auto generate number in jsp with the database connection mysql for employee number?   <%@page import="java.sql.
how to auto generate number in jsp with the database connection mysql for employee number?
how to auto generate number in jsp with the database connection mysql for employee number?  how to auto generate number in jsp with the database connection mysql for employee number?   <%@page import="java.sql.
Connection
Connection  What is Connection
connection
connection   how to make multiple database connection using jdbc
connection
connection   How to get connected to my database using jsp   Please visit the following links: http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp/displaydatafrom_database1.shtml http
common database jsp file for all the jsp files in the application
common database jsp file for all the jsp files in the application  hi... use of this single jsp file while connecting to database rather than writing connectivity code in all the jsp pages . send me the code for that . thanks
connection
the connection with the available port on the host machine: import java.net.... the connection was not established. Predict the output of the preceding code. Explain why the connection cannot be established
online quiz program coding using jsp, jdbc odbc connection with ms. access.. Thank you.
online quiz program coding using jsp, jdbc odbc connection with ms. access.. Thank you.  please provide online quiz program coding using jsp, jdbc odbc connection with ms. access.. Thank you.   Create table test
JSP to Excel - JSP-Servlet
JSP to Excel  Need an example of JSP and Excel database connection. Thanks
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
jsp
jsp  Hi How can we display sqlException in a jsp page? How can we mantain session in jsp? Thanks Kalins Naik   JSP SQL Exception <...;html> <head> <title>Connection with mysql database</title>
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection - JSP-Servlet
{ private Connection con; private PreparedStatement ps=null; public void init... ServletException("Initialization failed, Unable to get DB connection
Connection pooling
Connection pooling  What is Connection pooling
jsp
jsp   sir i am trying to connect the jsp with oracle connectivity... are using oracle oci driver,you have to use: Connection connection... are using oracle thin driver,you have to use: Connection connection
connection closing
connection closing  hello, what happens if connection is not closed
Connection pooling
Connection pooling  Sir, In my project i want to implement connection pooling with ms-sql server 2005. i wrote the code in JSP like this... ADS_TO_REPLACE_1 <% Connection con=DbCon.getConnection
jsp
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in the jsp file: /jsp/insertdate.jsp month cannot be resolved 4...(Calendar.MONTH); An error occurred at line: 17 in the jsp file: /jsp
jsp
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in the jsp file: /jsp/insertdate.jsp month cannot be resolved 4: 5: <% 6: String...); An error occurred at line: 17 in the jsp file: /jsp/insertdate.jsp Duplicate local
jsp
jsp  hai good morning all jsp beginner myself is sathishkumar i am developing a web application jsp. in this application i generate id card.how... { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn
jsp
jsp  how jsp translated into servlets
JSP
JSP  How to run jsp program in eclipse
jsp
jsp  how to create jsp page
Jsp
Jsp  Can I implement interface in jsp
JSP
what is JSP forward tag for  what is JSP forward tag for   It forwards the current request to another JSP page. Below is the syntax for the same:- <jsp:forward page="...url..." /> We can also forward parameter
jsp
jsp  how to include two jsp page

Ads