隨筆-1  評論-0  文章-0  trackbacks-0

          import java.sql.*;

          public class sqlOperate
          {
          ?private Connection con;
          ?
          ?public void connection()??
          ?{
          ??try?
          ??{
          ???? String url = "jdbc:odbc:LocalServer";
          ??????? Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          ???? con = DriverManager.getConnection(url,"sa","");
          ??}
          ??catch(Exception e)
          ??{
          ???System.out.println("沒有連接!");
          ??}
          ?}
          ?
          ?public void select()
          ?{??
          ????????? try
          ????????? {
          ?????????? Statement sel = con.createStatement();
          ?????????? ResultSet rs;
          ?????????? ?rs = sel.executeQuery("select * from student");??
          ?????????? while(rs.next())
          ??????????? {
          ????????????? System.out.println(rs.getString("sno")+" "+rs.getString("age"));
          ???????? ??? }
          ????????? }
          ??????? ?catch(Exception e)
          ???????? {
          ????????? System.out.println("查詢出錯");
          ????????? }
          ?}
          ?
          ?public static void main(String[] args)
          ?{
          ??sqlOperate a = new sqlOperate();
          ??a.connection();
          ???????? a.select();
          ?}
          }

          posted on 2007-03-24 11:04 heyibofly 閱讀(114) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 无为县| 玉树县| 铜梁县| 彭山县| 恩施市| 衡东县| 阿坝县| 修武县| 古丈县| 铁岭县| 宁晋县| 宜城市| 德化县| 开封县| 丰台区| 如皋市| 呼图壁县| 固镇县| 麟游县| 灵石县| 丽江市| 秦安县| 芦溪县| 清远市| 甘孜| 墨竹工卡县| 广宗县| 滨海县| 抚远县| 宜兴市| 陵川县| 潞城市| 卢龙县| 嘉荫县| 健康| 兴和县| 梁河县| 姚安县| 梁山县| 含山县| 申扎县|