myeclipse怎么看连的哪个数据库
答案:2 悬赏:0 手机版
解决时间 2021-03-15 13:19
- 提问者网友:夢醒日落
- 2021-03-15 02:32
myeclipse怎么看连的哪个数据库
最佳答案
- 五星知识达人网友:鱼忧
- 2021-03-15 03:14
自己写一个程序连接 要那简单的SQL举例子import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;public class Datalink {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=你的数据库名字";
String user = "数据库用户名";
String key = "密码";
public Datalink(){}
public Datalink(String driver,String url,String user,String key)
{
this.driver = driver;
this.url = url;
this.user = user;
this.key = key;
}
public Connection openData()
{
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, key);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public void closeData(Connection con)
{
if(con != null)
{
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
import java.sql.DriverManager;
import java.sql.SQLException;public class Datalink {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=你的数据库名字";
String user = "数据库用户名";
String key = "密码";
public Datalink(){}
public Datalink(String driver,String url,String user,String key)
{
this.driver = driver;
this.url = url;
this.user = user;
this.key = key;
}
public Connection openData()
{
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, key);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public void closeData(Connection con)
{
if(con != null)
{
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
全部回答
- 1楼网友:人间朝暮
- 2021-03-15 03:45
sqlserver2005默认情况下是禁用了tcp/ip连接。启动tcp/ip连接的方法, 打开 \microsoft sql server 2005\配置工具\目录下的sql server configuration manager,选择mssqlserver协议, 然后右边窗口有个tcp/ip协议,然后启动它,把sqlserver服务停了,然后在启动。问题就解决了 有一个小小的地方需要改善一下... 在启动tcp/ip协议后还要把其属性中的tcp端口号改为1433,再把服务停了,再启动,就ok了啊
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯