标题:JAVA向数据库添加数据 有一个问题 大家帮忙看看! 谢谢了
取消只看楼主
elan1986
Rank: 6Rank: 6
等 级:贵宾
威 望:18
帖 子:458
专家分:407
注 册:2007-12-17
结帖率:100%
 问题点数:0 回复次数:0 
JAVA向数据库添加数据 有一个问题 大家帮忙看看! 谢谢了
package lch;

import java.sql.*;

public class tianjiaguanliyuan
{
    public static Connection conn;
    public static Statement stmtl;
    public static ResultSet rs=null;
    public static final String ACS_CON_STR="sun.jdbc.odbc.JdbcOdbcDriver";
    public static PreparedStatement ps;

    public static Connection getConnect(String url)
    {
        Connection conn=null;
        try
        {    
            Class.forName(ACS_CON_STR);
            conn=DriverManager.getConnection(url);
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return conn;
    }
    
    public static boolean disconnect()
    {
        boolean successed=false;
        try{
            if(conn!=null) conn.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return successed;
    }

    public static void prepareStatement1()
    {
        String sql = "insert into dl values (gg,123)";
        PreparedStatement ps;
        try{
        ps=conn.prepareStatement(sql);
        ps.setString(2,"sql");
        ps.executeUpdate();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        
    }
    public static boolean CloseResltSet()
    {
        boolean successed=false;
        try{
            if(rs!=null) rs.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return successed;
    }
    public static void main(String[] args)
    {
    //String mm="insert into dl values (gg,123)";
    getConnect("jdbc:odbc:library");
    prepareStatement1();
    }
}
搜索更多相关主题的帖子: JAVA 数据库 public static Connection 
2008-05-22 15:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-215614-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.117672 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved