数据库连接小问题 我是学.NET的,但公司让我转JAVA我手头一点基础的资料都没有,上网找的资料都很复杂谁可以给我些段最简单的JAVA连接数据库的代码简单的就好,我自己研究这个过程,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【hai2feng3】截止到2008-07-07 10:15:20的历史汇总数据(不包括此帖):发帖的总数量:13 发帖的总分数:350 结贴的总数量:10 结贴的总分数:280 无满意结贴数:4 无满意结贴分:80 未结的帖子数:3 未结的总分数:70 结贴的百分比:76.92 % 结分的百分比:80.00 % 无满意结贴率:40.00 % 无满意结分率:28.57 % 楼主加油 这里有个最简单的实例,可以参考一下: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()); }*/ } //***********************************************************/ } 参考这个看看,一个是学习笔记,一个是连接SQL Server的代码http://www.java2000.net/viewthread.jsp?tid=4596http://www.java2000.net/viewthread.jsp?tid=171其它数据库的链接,可以到精华区找一个文章 这里是一个例子:http://yiding-he.javaeye.com/admin/blogs/212265 此GUI的样式效果是怎么做的? 【请教高手】在Jtable上怎样实现直接修改数据的功能? 快速排序总少一次 Java初学者,请指点 如何编写java程序把word转换成pdf? 一个项目如何import另一个项目的package的类? 如何读取一个整数 请问有人会用C调Java么? 如何使visual java++支持swing工具包?? 新手求问啊 JSP里面怎么获得一个input的value 请教 java考试题
楼主【hai2feng3】截止到2008-07-07 10:15:20的历史汇总数据(不包括此帖):
发帖的总数量:13 发帖的总分数:350
结贴的总数量:10 结贴的总分数:280
无满意结贴数:4 无满意结贴分:80
未结的帖子数:3 未结的总分数:70
结贴的百分比:76.92 % 结分的百分比:80.00 %
无满意结贴率:40.00 % 无满意结分率:28.57 %
楼主加油
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());
}*/
}
//***********************************************************/
}
http://www.java2000.net/viewthread.jsp?tid=4596
http://www.java2000.net/viewthread.jsp?tid=171其它数据库的链接,可以到精华区找一个文章
http://yiding-he.javaeye.com/admin/blogs/212265