b) 连接到一个SQL Server数据库。 Connection connection = null ; try { //load the jdbc driver ; String driverName = “com.microsoft.jdbc.sqlserver.SQLServerDriver”; Class.forName(driverName).newInstance(); //create a connection to the database; String serverName = “127.0.0.1”; String serverPort = “1433”; String serverID = serverName + serverPort ; String userName = “hello”; String userPsw = “world”; String url = “jdbc:JSQLConnect ://” + serverID ; Connection = DriverManager.getConnection(url , userName , userPsw); } catch(ClassNotFoundException e1) { //catch could not find database driver exception. } catch(SQLException e2) { //catch could not connect to the database exception. } |
闂傚倷娴囬妴鈧柛瀣崌閺岀喖顢涘⿰鍐炬毉濡炪們鍎查崹鍧楀蓟閻旇 鍋撳☉娅亝鎱ㄩ崶褉鏀芥い鏇炴鐎氾拷闂傚倷绀侀幖顐ゆ偖椤愶箑纾块柛鎰嚋閼板潡鏌涘☉娆愮稇缂備讲鏅犻弻鐔碱敍濠婂喚鏆銈冨劵閹凤拷>>
正在阅读:Java连接数据库谈Java连接数据库谈
2004-04-07 14:31
出处:CSDN
责任编辑:sdq
键盘也能翻页,试试“← →”键