Computers & Internet Logo

Related Topics:

Posted on Feb 27, 2009

How to connect from jsp login page to database

Source code for connecting jsp login page to database through jdbc

2 Answers

Anonymous

Level 1:

An expert who has achieved level 1.

Corporal:

An expert that has over 10 points.

Mayor:

An expert whose answer got voted for 2 times.

Problem Solver:

An expert who has answered 5 questions.

  • Contributor 16 Answers
  • Posted on Feb 28, 2009
Anonymous
Contributor
Level 1:

An expert who has achieved level 1.

Corporal:

An expert that has over 10 points.

Mayor:

An expert whose answer got voted for 2 times.

Problem Solver:

An expert who has answered 5 questions.

Joined: Feb 27, 2009
Answers
16
Questions
0
Helped
7384
Points
20

Hey try this code......just found it on the net... Put the code in tomcat and test the application through browser. The browser should display the display the data stored in the table.

Here is the code of our JSP file
<%@ page language="java" import="java.sql.*"%>
<html>
<head><title>Read from mySQL Database</title>
</head>
<body>

<p align="center"><b>Following records are selected from the 'jakartaproject' table.</b><br>&nbsp;</p>

<div align="center" width="85%">
<center>
<table border="1" borderColor="#ffe9bf" cellPadding="0" cellSpacing="0" width="658" height="63">
<tbody>
<td bgColor="#008080" width="47" align="center" height="19"><font color="#ffffff"><b>Sr.
No.</b></font></td>
<td bgColor="#008080" width="107" height="19"><font color="#ffffff"><b>Project</b></font></td>
<td bgColor="#008080" width="224" height="19"><font color="#ffffff"><b>Url
Address</b></font></td>
<td bgColor="#008080" width="270" height="19"><font color="#ffffff"><b>Description
of the project</b></font></td>

<%
String DRIVER = "org.gjt.mm.mysql.Driver";
Class.forName(DRIVER).newInstance();


Connection con=null;
ResultSet rst=null;
Statement stmt=null;

try{
String url="jdbc:mysql://192.168.10.2/tutorial?user=tutorial&password=tutorial";

int i=1;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
rst=stmt.executeQuery("select * from jakartaproject ");
while(rst.next()){

if (i==(i/2)*2){
%>
<tr>
<td bgColor="#ffff98" vAlign="top" width="47" align="center" height="19"><%=i%>.</td>
<td bgColor="#ffff98" vAlign="top" width="107" height="19"><%=rst.getString(2)%></td>
<td bgColor="#ffff98" vAlign="top" width="224" height="19"><a rel='nofollow' href="<%=rst.getString(3)%>"><%=rst.getString(3)%></a>&nbsp;</td>
<td bgColor="#ffff98" vAlign="top" width="270" height="19"><%=rst.getString(4)%></td>
</tr>
<%
}else{
%>
<tr>
<td bgColor="#ffcc68" vAlign="top" width="47" align="center" height="19"><%=i%>.</td>
<td bgColor="#ffcc68" vAlign="top" width="107" height="19"><%=rst.getString(2)%></td>
<td bgColor="#ffcc68" vAlign="top" width="224" height="19"><a rel='nofollow' href="<%=rst.getString(3)%>"><%=rst.getString(3)%></a>&nbsp;</td>
<td bgColor="#ffcc68" vAlign="top" width="270" height="19"><%=rst.getString(4)%></td>
</tr>
<% }

i++;
}
rst.close();
stmt.close();
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
%>

</tbody>
</table>
</center>
</div>


</body>
</html>

mercyemma18

Level 1:

An expert who has achieved level 1.

  • Contributor 1 Answer
  • Posted on Feb 21, 2012
mercyemma18
Contributor
Level 1:

An expert who has achieved level 1.

Joined: Jan 30, 2012
Answers
1
Questions
1
Helped
3918
Points
0

I want to uesd my faecbook

Ad

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

I want ot link my inventory database to another pc

Create user account for second system in Sql
If u want to get data by code means u need to create
connection to database by using jdbc connection string .
then write a query to acces data.
create statement
pass query to that statement
run query

Statement statement=con.createstatement();
statement.executequery(querystring);
0helpful
2answers

To access data in the database using java

Your question is ambiguously worded. What I believe you are asking is how can you read an MS Access database from a Java program. (If that is not the case, then please re-phrase your question).

Java 1.7 :
Java JDBC: An example to connect MS Access database
Java 1.8 : JDBC: An example to connect MS Access database in Java 8
For other databases,
My SQL database : Java JDBC: An example to connect MySQL database
Oracle database : Java JDBC: An example to connect Oracle database

Source:

Best java training institute in chennai
Best Java Training in Chennai Java training Institute


admin-java_logo-wa2edogpcpakk0ecm2enjvq3-3-0.png
0helpful
1answer

How to make a connection with sybase using jtds driver

hi,

the first thing you need is the correct JDBC driver, that must be included with your database.
Then you need to create a connection using the driver.

This link could help.

http://www.redmountainsw.com/wordpress/archives/jdbc-connection-urls

regards
0helpful
1answer

How to write jdbc connections

http://www.jdbc-tutorial.com/

window.google_render_ad();

welcome_title_image.gif Java JDBC Tutorial Java JDBC Tutorial
The JDBC ( Java Database Connectivity) API defines interfaces and classes for writing database applications in Java by making database connections. Using JDBC you can send SQL, PL/SQL statements to almost any relational database. JDBC is a Java API for executing SQL statements and supports basic SQL functionality. It provides RDBMS access by allowing you to embed SQL inside Java code. Because Java can run on a thin client, applets embedded in Web pages can contain downloadable JDBC code to enable remote database access. You will learn how to create a table, insert values into it, query the table, retrieve results, and update the table with the help of a JDBC Program example.


window.google_render_ad();
Although JDBC was designed specifically to provide a Java interface to relational databases, you may find that you need to write Java code to access non-relational databases as well.
JDBC Architecture jdbc.jpg Java application calls the JDBC library. JDBC loads a driver which talks to the database. We can change database engines without changing database code.
JDBC Basics - Java Database Connectivity Steps Before you can create a java jdbc connection to the database, you must first import the
java.sql package.
import java.sql.*; The star ( * ) indicates that all of the classes in the package java.sql are to be imported.
1. Loading a database driver,
In this step of the jdbc connection process, we load the driver class by calling Class.forName() with the Driver class name as an argument. Once loaded, the Driver class creates an instance of itself. A client can connect to Database Server through JDBC Driver. Since most of the Database servers support ODBC driver therefore JDBC-ODBC Bridge driver is commonly used.
The return type of the Class.forName (String ClassName) method is “Class”. Class is a class in
java.lang package.
try { Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”); //Or any other driver } catch(Exception x){ System.out.println( “Unable to load the driver class!” ); } 2. Creating a oracle jdbc Connection

The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. DriverManager is considered the backbone of JDBC architecture. DriverManager class manages the JDBC drivers that are installed on the system. Its getConnection() method is used to establish a connection to a database. It uses a username, password, and a jdbc url to establish a connection to the database and returns a connection object. A jdbc Connection represents a session/connection with a specific database. Within the context of a Connection, SQL, PL/SQL statements are executed and results are returned. An application can have one or more connections with a single database, or it can have many connections with different databases. A Connection object provides metadata i.e. information about the database, tables, and fields. It also contains methods to deal with transactions.
JDBC URL Syntax:: jdbc: <subprotocol>: <subname> JDBC URL Example:: jdbc: <subprotocol>: <subname>•Each driver
0helpful
1answer

How can i connect jdbc odbc to do my program

Create a System DSN in Windows XP loadTOCNode(2, 'summary');
  1. Click Start, point to Control Panel, double-click Administrative Tools, and then double-click Data Sources(ODBC).
  2. Click the System DSN tab, and then click Add.
  3. Click the database driver that corresponds with the database type to which you are connecting, and then click Finish.
  4. Type the data source name. Make sure that you choose a name that you can remember. You will need to use this name later.
  5. Click Select.
  6. Click the correct database, and then click OK.
  7. Click OK, and then click OK.
0helpful
1answer

I can't connect the ms-sql 2005 database with flex

hi this is jesica am expert to help you to fix this issue for you,kindly call me on +1(518)348-9393 and we will be glad to help you.
1helpful
1answer

Hibernate configuration with windows authentication

When you login to your database (download the management tool) right click on server name->properties->security.

There you can choose mixed authentication.
0helpful
1answer

Oracle SQL Error

Does it connect after the error ?. First try to connect from your client to Oracle server using SQL plus client.

Second - Do a tnsping <server name>

This will give you the correct Host name, SID and Port number.

Make sure that your JDBC connection parameters match with the actual connection from TNS output
0helpful
1answer

MyEclipse6.0.1 connection with sqlserver 2000

hi


Try with MS SqlServer 2005 JDBC Driver,
i had a similar problem with 2000 jdbc driver
Not finding what you are looking for?

3,928 views

Ask a Question

Usually answered in minutes!

Top Compaq Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

Brad Brown

Level 3 Expert

19187 Answers

ExpressFiX
ExpressFiX

Level 2 Expert

691 Answers

Are you a Compaq Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...