sql server jdbc
2008-08-20 14:09
176 查看
package com.cjt.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MssqlJtds {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = null;
Statement stmt = null;
ResultSet rs =null;
String url = "jdbc:jtds:sqlserver://localhost:1433/pubs";
conn = DriverManager.getConnection(url,"sa","sa");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from authors");
while(rs.next())
{
System.out.println(rs.getObject(1));
}
stmt.close();
conn.close();
}
}
//另一种方法
package com.cjt.jdbc;
import java.sql.Connection;
public class MssqlCom {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = null;
Statement stmt = null;
ResultSet rs =null;
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
conn = DriverManager.getConnection(url,"sa","sa");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from authors");
while(rs.next())
{
System.out.println(rs.getObject(1));
}
stmt.close();
conn.close();
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MssqlJtds {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = null;
Statement stmt = null;
ResultSet rs =null;
String url = "jdbc:jtds:sqlserver://localhost:1433/pubs";
conn = DriverManager.getConnection(url,"sa","sa");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from authors");
while(rs.next())
{
System.out.println(rs.getObject(1));
}
stmt.close();
conn.close();
}
}
//另一种方法
package com.cjt.jdbc;
import java.sql.Connection;
public class MssqlCom {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = null;
Statement stmt = null;
ResultSet rs =null;
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
conn = DriverManager.getConnection(url,"sa","sa");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from authors");
while(rs.next())
{
System.out.println(rs.getObject(1));
}
stmt.close();
conn.close();
}
}
相关文章推荐
- com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败
- com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection timed out: connect数据库
- jsp - java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
- com.microsoft.sqlserver.jdbc.SQLServerException: socket closed
- com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。
- microsoft JDBC Driver for SQL Server
- 完全jdbc操作 mysql Oracle sqlserver 链接类 不指定
- jdbc sqlserver oracle 驱动问题集锦
- com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 ‘xxx' 无效
- JDBC操作 SQL SERVER之数据的分页显示
- 关于在java中连接MS SQL Server 2005 JDBC的问题及解决办法
- Tomcat + SQL Server 2005 + jsp : ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver 问题的解决
- eclipse 连接 sqlserver2005错误信息:"java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver"
- com.microsoft.sqlserver.jdbc.SQLServerException: 不支持此服务器版本。目标服务器必须是 SQL Server 2000 或更高版本。
- Mysql/SQLServer数据类型对应的JDBC类型、JAVA类型,数据类型长度 速查表
- sql server JDBC连接字串
- JSP中使用JDBC驱动访问MS SQL SERVER数据库的例子
- 关于在java中连接MS SQL Server 2005 JDBC的问题及解决办法
- java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver问题解决
- jTDS - SQL Server and Sybase JDBC driver