当前位置: 代码迷 >> Java Web开发 >> jsp中jdbc-odbj连接问题?(已解决)
  详细解决方案

jsp中jdbc-odbj连接问题?(已解决)

热度:103   发布时间:2008-08-02 15:53:23.0
jsp中jdbc-odbj连接问题?(已解决)
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.sql.*" %>
<%!
    Connection conn=null;
    Statement stmt=null;
%>
<%
    //1、加载数据库驱动
    try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }catch(Exception e){
        e.printStackTrace();
        out.print("数据库驱动加载失败!");
    }
    
    //2、连接数据库
    try{
        conn=DriverManager.getConnection("jdbc:odbc:mldn");
    }catch(Exception e){
        out.print("数据库连接失败");
    }
    
    //3、操作数据库
    try{
        stmt=conn.createStatement();
        stmt.executeUpdate("INSERT INTO person(name,password,age) VALUES('simple','123','20')");
    }catch(Exception e){
        out.print("数据库操作失败!");
    }

%>

[[it] 本帖最后由 he20041987 于 2008-8-2 17:54 编辑 [/it]]
搜索更多相关主题的帖子: jsp  

----------------解决方案--------------------------------------------------------
  相关解决方案