This is a simple jdbc odbc bridge connection.
First, you must create a database. Open the control panel and set the data source name to TestData in the configuration system dsn.
Import java. SQL .*;
Class SqlTest
{
Public static void main (String [] args) throws Exception
{
String driver = "sun. jdbc. odbc. JdbcOdbcDriver ";
String url = "jdbc: odbc: TestData"; // the data source name is TestData.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Try
{
Class. forName (driver );
Con = DriverManager. getConnection (url );
Stmt = con. createStatement ();
Rs1_stmt.exe cuteQuery ("select * from adm"); // The table name is adm.
While (rs. next ())
{
String s1 = rs. getString ("ID ");
System. out. println (s1 );
String s2 = rs. getString ("admin ");
System. out. println (s2 );
String s3 = rs. getString ("password ");
System. out. println (s3 );
}
} Catch (Exception e)
{
E. printStackTrace ();
}
Rs. close ();
Con. close ();
}
}
The following is the jsp implementation (basically the same ):
<% @ Page contentType = "text/html" %>
<% @ Page pageEncoding = "UTF-8" %>
<% @ Page import = "java. SQL. *" %>
<Html>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Head>
<Title> JDBCTest Page </title>
</Head>
<Body>
<H1> JDBCTest Page <Table border = "1" align = "center">
<Thead>
<Tr>
<Th> </th>
<Th> </th>
<Th> </th>
<Th> </th>
<Th> </th>
</Tr>
</Thead>
<Tr>
<Td> ID </td>
<Td> User: </td>
<Td> password: </td>
<! -- Td> E-MAIL: <td -->
<Td> email password: </td>
</Tr>
<%
Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
String url = "jdbc: odbc: TestData ";
String username = "";
String password = "";
Connection con = DriverManager. getConnection (url, username, password );
Statement stmt = con. createStatement ();
ResultSet rs1_stmt.exe cuteQuery ("select * from adm ");
While (rs. next ())
{
%>
<Tr>
<Td> <% = rs. getString ("ID") %> </td>
<Td> <% = rs. getString ("admin") %> </td>
<Td> <% = rs. getString ("password") %> </td>
</Tr>
<%
}
Rs. close ();
Con. close ();
%>
</Table>
</Body>
</Html>