Mysql,SQL Server 2000,Oracle四种数据库的连接
<%! String trans(String chi) { String result = null; byte temp []; try { temp=chi.getBytes("iso-8859-1"); result = new String(temp); } catch(UnsupportedEncodingException e) { System.out.println (e.toString()); } return result; } %> <% Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=books","sa",""); Statement stmt=con.createStatement(); ResultSet rst=stmt.executeQuery("select * from book"); while(rst.next()) { out.println("<tr>"); out.println("<td>"+rst.getString("bookId")+"</td>"); out.println("<td>"+trans(rst.getString("bookName"))+"</td>"); out.println("<td>"+trans(rst.getString("publisher"))+"</td>"); out.println("<td>"+rst.getFloat("price")+"</td>"); out.println("</tr>"); } //关闭连接、释放资源 rst.close(); stmt.close(); con.close(); %> </table> </body> </html>