当前位置: 技术问答>java相关
要建立到MSSQL的连接,Class.forName与URL应怎样写?
来源: 互联网 发布时间:2015-08-13
本文导语: 要建立到MSSQL的连接,Class.forName与URL应怎样写? | 如果使用jdbc.odbc桥,这么写: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver()"); String url = "jdbc:odbc:yourconnection"; | 给你段例子吧? import ...
要建立到MSSQL的连接,Class.forName与URL应怎样写?
|
如果使用jdbc.odbc桥,这么写:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver()");
String url = "jdbc:odbc:yourconnection";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver()");
String url = "jdbc:odbc:yourconnection";
|
给你段例子吧?
import java.sql.*;
public class test{
public static void main(String[] args)
{
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:topubs","Administrator","Administrator");//topubs是odbc数据源
rs=conn.createStatement().executeQuery("select * from employee");
while(rs.next())
System.out.println(rs.getString("fname"));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
import java.sql.*;
public class test{
public static void main(String[] args)
{
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:topubs","Administrator","Administrator");//topubs是odbc数据源
rs=conn.createStatement().executeQuery("select * from employee");
while(rs.next())
System.out.println(rs.getString("fname"));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
|
org.gjt.mm.mysql.Driver