jdbc 和 SQL 怎么连接

fjeros 2003-12-29 11:11:37
设定和驱动我都做了 就是连接命令不知道怎么写 有例子吗 借我看看
...全文
41 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xtal 2003-12-29
  • 打赏
  • 举报
回复
import java.sql.*;

//jdbc-odbc bridge

public class SQLTest{
public static void main(String[] args) throws Exception {
String url="jdbc:odbc:SQLServer1";

Connection conn;

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("found");
}
catch(Exception e){
e.printStackTrace( );
System.out.println("no found");
}
try{
conn=DriverManager.getConnection(url,"sa","sa");
System.out.println("connection sucessful");
}
catch(Exception e){
e.printStackTrace( );
System.out.println("connection fail");
}
}
}

type4的和这个类似,就不写了。

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧