| 发表于:2007-06-15 14:57:547楼 得分:0 |
给你个现成的 import java.sql.*; public class odbcdemo{ private string dburl= "jdbc:odbc:canyin "; //数据库标识名 private string user= "sa "; //数据库用户 private string password= "bestun1 "; //数据库用户密码 public odbcdemo(){ try { class.forname( "sun.jdbc.odbc.jdbcodbcdriver "); //装载数据库驱动 connection con=drivermanager.getconnection(dburl,user,password); //得到连接 system.out.println(con.getcatalog()); //打印当前数据库目录名称 system.out.println( "连接成功 "); con.close(); //关闭连接 } catch (exception ex) { ex.printstacktrace(); //输出出错信息 } } public static void main(string args[]){ new odbcdemo(); } } | | |
|