当前位置: 技术问答>java相关
[初学者问题]我现在配置好了Tomcat,想连接SQLserver,需要下载什么文件吗?
来源: 互联网 发布时间:2015-10-21
本文导语: 如题,是不是要下载JDBC驱动?在那有得下?可以写个简单的例子出来吗?如连接数据库后显示表中的物品名。谢谢! | 用jdbc-odbc连接sqlserver odbc数据源的话不要 否则要用sqlserver的jdbc driver 微...
如题,是不是要下载JDBC驱动?在那有得下?可以写个简单的例子出来吗?如连接数据库后显示表中的物品名。谢谢!
|
用jdbc-odbc连接sqlserver odbc数据源的话不要
否则要用sqlserver的jdbc driver
微软有提供,伴随文档有例子
否则要用sqlserver的jdbc driver
微软有提供,伴随文档有例子
|
迟来了一步,
try{
InputStream ins = new FileInputStream("DBConfig.ini");
Properties pr = new Properties();
pr.load(ins);
String dbname = pr.getProperty("DataBaseName","").trim();
String ip = pr.getProperty("IPAddress","localhost").trim();
user = pr.getProperty("username","").trim();
passwd = pr.getProperty("password","").trim();
url = "jdbc:weblogic:mssqlserver4:"+dbname+"@"+ip+":1433";
Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
DriverManager.setLoginTimeout(50);
con = DriverManager.getConnection(url,user,passwd);
String sql = "select * from tbname";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql)
rs.getString(1);
try{
InputStream ins = new FileInputStream("DBConfig.ini");
Properties pr = new Properties();
pr.load(ins);
String dbname = pr.getProperty("DataBaseName","").trim();
String ip = pr.getProperty("IPAddress","localhost").trim();
user = pr.getProperty("username","").trim();
passwd = pr.getProperty("password","").trim();
url = "jdbc:weblogic:mssqlserver4:"+dbname+"@"+ip+":1433";
Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
DriverManager.setLoginTimeout(50);
con = DriverManager.getConnection(url,user,passwd);
String sql = "select * from tbname";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql)
rs.getString(1);