-
Servlet connection
Here folks, I have the following codes which connects to a an access database directly and reads data, I want to do same connection in servlet or JSP, how do I do that
import java.sql.*;
public class Test
{
public static void main(String[] args)
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "P:/javanew/mdbTEST.mdb";
String database = "jdbc dbc river={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
Statement s = con.createStatement();
//s.execute("create table TEST12345 ( column_name integer )"); // create a table
//s.execute("insert into TEST12345 values(1)"); // insert some data into the table
s.execute("select * from Protein"); // select the data from the table
ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
if (rs != null) // if rs == null, then there is no ResultSet to view
System.out.print("ProteinKey");
while ( rs.next() ) // this will step through our data row-by-row
{
/* the next line will get the first column in our current row's ResultSet
as a String ( getString( columnNumber) ) and output it to the screen */
System.out.println( rs.getString(1)+ " "+ rs.getString(2)+ " "+rs.getString(3)+ " "+rs.getString(4)+ " "+rs.getString(5) +" "+rs.getString(6) );
// System.out.println(ProteinKey + ". " + Author + ", " + ID + " (" + AC + ")");
}
s.execute("drop table Protein");
s.close(); // close the Statement to let the database know we're done with it
con.close(); // close the Connection to let the database know we're done with it
}
catch (Exception err) {
System.out.println("ERROR: " + err);
}
}
}
//save this code into a file called Test.java and compile it
Similar Threads
-
Replies: 1
Last Post: 07-15-2005, 10:09 AM
-
Replies: 1
Last Post: 09-12-2000, 11:51 AM
-
Replies: 0
Last Post: 08-16-2000, 02:18 PM
-
Replies: 1
Last Post: 08-10-2000, 12:35 PM
-
Replies: 1
Last Post: 08-10-2000, 12:33 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks