我是学.NET的,但公司让我转JAVA
我手头一点基础的资料都没有,上网找的资料都很复杂
谁可以给我些段最简单的JAVA连接数据库的代码
简单的就好,我自己研究这个过程,谢谢

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【hai2feng3】截止到2008-07-07 10:15:20的历史汇总数据(不包括此帖):
    发帖的总数量:13                       发帖的总分数:350                      
    结贴的总数量:10                       结贴的总分数:280                      
    无满意结贴数:4                        无满意结贴分:80                       
    未结的帖子数:3                        未结的总分数:70                       
    结贴的百分比:76.92 %               结分的百分比:80.00 %                  
    无满意结贴率:40.00 %               无满意结分率:28.57 %                  
    楼主加油
      

  2.   

    这里有个最简单的实例,可以参考一下:
    public class TestConnect {
    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://127.0.0.1:3306;DatabaseName = db1";
    /**/
    private static String user = "root";
    private static String password = "jinsheng";

    public static Connection getConnection(){
    Connection con;
    try{
    Class.forName(driver);
    con = DriverManager.getConnection(url, user, password);
    System.out.println("success");
    return con;
    }catch(ClassNotFoundException e){
    System.out.println(e.getMessage());
    System.out.println("ClassNotFound");
    }catch(SQLException e){
    System.out.println(e.getMessage());
    System.out.println("SQLNotFound");
    }
    return null;
    }


    //*******************************************************
    public static void main(String [] args){
    TestConnect con1 = new TestConnect();
    //Connection connect = con1.getConnection();
    Connection connect = TestConnect.getConnection();
    //Chengyu chy = con1.getChy(connect);

    /*if (chy!=null){
    System.out.println("id = " + chy.getId());
    System.out.println("headno = " + chy.getHeadno());
    System.out.println("endno = " + chy.getEndno());
    System.out.println("word = " + chy.getWord());
    }*/

    }
    //***********************************************************/

    }
      

  3.   

    参考这个看看,一个是学习笔记,一个是连接SQL Server的代码
    http://www.java2000.net/viewthread.jsp?tid=4596
    http://www.java2000.net/viewthread.jsp?tid=171其它数据库的链接,可以到精华区找一个文章
      

  4.   

    这里是一个例子:
    http://yiding-he.javaeye.com/admin/blogs/212265