注册 登录
编程论坛 J2EE论坛

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

he20041987 发布于 2008-08-02 15:53, 1055 次点击
<%@ 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]]
0 回复
1