锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品VA在线看黑人,亚洲91av视频,亚洲精品中文字幕无码蜜桃http://www.tkk7.com/Yang/category/9716.html瀛﹁?鎵浠ヤ慨鎬т篃.瑙?鍚?璦,璨?鎬?鎬т箣鎵鏈変篃.瀛﹀垯姝?鍚﹀垯閭? 澶辮觸鏄洜涓烘斁寮?涓嶆斁寮冨氨涓嶄細(xì)鏈夊け璐?zh-cnFri, 02 Mar 2007 11:49:41 GMTFri, 02 Mar 2007 11:49:41 GMT60Using DatabaseMetaDate and ResultSetMetaDatahttp://www.tkk7.com/Yang/articles/40073.html椋炴壃椋炴壃Sun, 09 Apr 2006 03:48:00 GMThttp://www.tkk7.com/Yang/articles/40073.htmlhttp://www.tkk7.com/Yang/comments/40073.htmlhttp://www.tkk7.com/Yang/articles/40073.html#Feedback0http://www.tkk7.com/Yang/comments/commentRss/40073.htmlhttp://www.tkk7.com/Yang/services/trackbacks/40073.html example for using DatabaseMetaData and ResultSetMetaData
package coreservlet;

import java.io.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
聽*
聽* @author DuYang
聽* @version
聽*/
public class NorthwindServlet extends HttpServlet {
聽聽聽
聽聽聽 /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
聽聽聽聽 * @param request servlet request
聽聽聽聽 * @param response servlet response
聽聽聽聽 */
聽聽聽
聽聽聽 /** A simple servlet that connects to a database and presents the results from the query in an
聽聽聽聽 *聽 HTML table.Ther driver,URL,username,,passwrd, and query are taken from input prarmeters.
聽聽聽聽 */
聽聽聽 protected void doPost(HttpServletRequest request, HttpServletResponse response)
聽聽聽 throws ServletException, IOException {
聽聽聽聽聽聽聽 response.setContentType("text/html");
聽聽聽聽聽聽聽 PrintWriter out=response.getWriter();
聽聽聽聽聽聽聽 String docType=
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 "+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "Transitional//EN\"\n";
聽聽聽聽聽聽聽 String title="Northwind Results";
聽聽聽聽聽聽聽 out.println(docType+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "<HTML>\n"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "<HEAD><TITLE>"+title+"</TITLE></HEAD>\n"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "<BODY BGCOLOR=\"#FDF5E6\"><CENTER>\n"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "<H1>Database Results</H1>\n");
聽聽聽聽聽聽聽 String driver=request.getParameter("driver");
聽聽聽聽聽聽聽 String url=request.getParameter("url");
聽聽聽聽聽聽聽 String username=request.getParameter("username");
聽聽聽聽聽聽聽 String password=request.getParameter("password");
聽聽聽聽聽聽聽 String query=request.getParameter("query");
聽聽聽聽聽聽聽 showTable(driver,url,username,password,query,out);
聽聽聽聽聽聽聽 out.println("</CENTER></BODY></HTML>");
聽聽聽 }
聽聽聽聽聽聽聽 public void showTable(String driver,String url,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 String username,String password,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 String query,PrintWriter out)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽 try
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //load database driver if it's not already loaded.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Class.forName(driver);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Establish netword connection to database.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Connection connection=
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 DriverManager.getConnection(url,username,password);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Look up info about the database as a whole.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 DatabaseMetaData dbMetaData=connection.getMetaData();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 out.println("<UL>");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 String productName=
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 dbMetaData.getDatabaseProductName();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 String productVersion=
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 dbMetaData.getDatabaseProductVersion();

聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 out.println("<LI><B>Database:</B>"+productName+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "<LI><B>Version:</B>"+productVersion+"</UL>");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Statement statement=connection.createStatement();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Send query to database and store queries.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ResultSet resultSet=statement.executeQuery(query);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Print result.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ResutlSetMetaData resultSetMetaData=
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 resultSet.getMetaData();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 int columCount=resultSetMetaData.getColumnCount();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 out.println("<TR>");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Column index statrs at 1(a la SQL), not 0(a la Java).
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 for(int i=1;i<columnCount;i++)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 out.println("<TH>"+resultSetMetaDate.getColumnName(i));
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 out.println();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Step through each row, retrieving the data in each
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 // column cell as String.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 for(int i=1;i<columnCount;i++)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 out.println("<TD>"+resultSet.getString(i));
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽 out.println();
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽 out.println("</TABLE>");
聽聽聽聽聽聽聽聽聽聽聽聽 connection.close();
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 catch(ClassNotFoundException e)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 System.err.println("Error loading driver:"+e);
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 catch(SQLException e1)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 System.err.println("Error connecting:"+e1);
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 catch(Exception ee)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 System.err.println("Error with input:"+ee);
聽聽聽聽聽聽聽 }
聽聽聽 }
聽聽聽 private static void showResults(ResultSet results)throws SQLException
聽聽聽 {
聽聽聽聽聽聽聽 while(results.next())
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 System.out.println(results.getString(1)+"");
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 System.out.println("");
聽聽聽 }
聽聽聽 public static void printUsage()
聽聽聽 {
聽聽聽聽聽聽聽 System.out.println("Usage:PreparedStatements host"+"dbName username password"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "vendow [print].");
聽聽聽 }
聽}

NorthwindForm.htm

Query Input:

Driver:
URL:
Username:
Password:
Query:


椋炴壃 2006-04-09 11:48 鍙戣〃璇勮
]]>
Basic JDBC Examplehttp://www.tkk7.com/Yang/articles/40063.html椋炴壃椋炴壃Sun, 09 Apr 2006 02:42:00 GMThttp://www.tkk7.com/Yang/articles/40063.htmlhttp://www.tkk7.com/Yang/comments/40063.htmlhttp://www.tkk7.com/Yang/articles/40063.html#Feedback0http://www.tkk7.com/Yang/comments/commentRss/40063.htmlhttp://www.tkk7.com/Yang/services/trackbacks/40063.html T his exaple using JDBC-ODBC bridge drive program.Using table NorthwindTest.
NorthwindTest.java

package skyey.snow;
import java.sql.*:

/** A JDBC example that connects to the Microsoft Acess sample Northwind database,issues a simple SQL query to the
聽 *聽聽employee table, and prints the results.
*/

public class NorthwindTest {
聽聽聽 public static void main(String[] args)
聽聽聽 {
聽聽聽聽聽聽聽 String driver="sun.jdbc.odbc.JdbcOdbcDriver";
聽聽聽聽聽聽聽 String url="jdbc:odbc:Northwind";
聽聽聽聽聽聽聽 String username=""; //No username/password required
聽聽聽聽聽聽聽 String password=""; //for desktop access to MS Access.
聽聽聽聽聽聽聽 showEmployeeTable(driver,url,username,passwrd);
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 /** Query the employee table and print the first and
聽聽聽聽聽聽聽聽 *聽 last names.
聽聽聽聽聽聽聽聽 */

聽聽聽聽聽聽聽 public static void showEmployeeTable(String driver,String url,String username,String password)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽 try
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //load database driver if it's not already loaded.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Class.forName(driver);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Establish network connection to database.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Connection connection=
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 DriverManager.getConnection(url,username,password);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 System.out.println("Employees\n"+"=============================");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //Create a Statement for executing queries.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Statement statement=connection.clearWarnings();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 String query=
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 "select firstName,lastName form employee";
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //send query to database and store results.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ResultSet resultSet=statement.executeQuery(query);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //print results.
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 while(resultSet.next())
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 System.out.println(resultSet.getString("firstName")+"");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 System.out.println(resultSet.getString("lastName")+"");
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 connection.close();
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 catch(ClassNotFoundException e)
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 System.err.println("Error loading driver:"+e);
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽 catch(SQLException e1)
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 System.err.println("Error with connection:"+e1);
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽 }
}

from example we should konw how to write a simpleness class for Database connection,and in this example i find a very good method we should study that is we should connection two or much more class using :
public class NorthwindTest {
聽聽聽 public static void main(String[] args)
聽聽聽 {
聽聽聽聽聽聽聽 String driver="sun.jdbc.odbc.JdbcOdbcDriver";
聽聽聽聽聽聽聽 String url="jdbc:odbc:Northwind";
聽聽聽聽聽聽聽 String username=""; //No username/password required
聽聽聽聽聽聽聽 String password=""; //for desktop access to MS Access.
聽聽聽聽聽聽聽 showEmployeeTable(driver,url,username,passwrd);
聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 /** Query the employee table and print the first and
聽聽聽聽聽聽聽聽 *聽 last names.
聽聽聽聽聽聽聽聽 */

聽聽聽聽聽聽聽 public static void showEmployeeTable(String driver,String url,String username,String password)
聽聽聽聽聽聽聽 {}
if we do like this our codes will became short,simpleness and beautiful.

椋炴壃 2006-04-09 10:42 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲AV无码国产精品色午友在线| 亚洲国产精品久久久久久| 亚洲国产系列一区二区三区 | 日韩va亚洲va欧洲va国产| 思思久久99热免费精品6| 免费一级毛片不卡在线播放| 另类小说亚洲色图| 亚洲国产综合久久天堂| 一边摸一边桶一边脱免费视频 | 在线美女免费观看网站h| 国产婷婷高清在线观看免费| 男人天堂2018亚洲男人天堂| 全免费A级毛片免费看网站| 亚洲国产欧美国产综合一区| 国产一区二区视频免费| 日韩免费高清一级毛片| 亚洲人成在线免费观看| 亚洲综合色区中文字幕| 免费亚洲视频在线观看| A级毛片成人网站免费看| 亚洲日本一区二区三区| 中文字幕无码视频手机免费看| 亚洲乱码日产一区三区| 亚洲国产成人无码AV在线影院| 国产午夜免费秋霞影院| 国产免费一级高清淫曰本片| 亚洲国产精品lv| 成人看的午夜免费毛片| 一区二区三区免费精品视频| 亚洲AV永久无码精品| 久久99九九国产免费看小说| 国产成人综合亚洲绿色| 亚洲AV色香蕉一区二区| 国产一精品一av一免费爽爽| 亚洲人和日本人jizz| www.亚洲色图.com| 最近中文字幕无免费| 深夜A级毛片视频免费| 亚洲视频手机在线| 免费一级毛片不卡不收费| 亚洲一区二区三区免费视频|