当前位置: 技术问答>java相关
高分求解:Class.forName("com.inet.tds.TdsDriver").newInstance();
来源: 互联网 发布时间:2014-12-31
本文导语: 我在论坛看过许多次了 但总是运行不正确 错误:"java.lang.ClassNotFoundException: com.inet.tds.TdsDriver" 端口怎么设置(1433) 请各位大侠出手相助 import java.sql.*; // JDBC package public class sql_data { String url = "jdbc:inetdae:192.168.2.70...
我在论坛看过许多次了
但总是运行不正确
错误:"java.lang.ClassNotFoundException: com.inet.tds.TdsDriver"
端口怎么设置(1433)
请各位大侠出手相助
import java.sql.*; // JDBC package
public class sql_data {
String url = "jdbc:inetdae:192.168.2.70?sql7=true"; // use your hostname and port number here
String login = "sa"; // use your login here
String password =""; // use your password here
public Connection connection = null;
public Statement st = null;
public ResultSet rs = null;
public sql_data(){
try {
Class.forName("com.inet.tds.TdsDriver").newInstance();
DriverManager.setLoginTimeout(10);
但总是运行不正确
错误:"java.lang.ClassNotFoundException: com.inet.tds.TdsDriver"
端口怎么设置(1433)
请各位大侠出手相助
import java.sql.*; // JDBC package
public class sql_data {
String url = "jdbc:inetdae:192.168.2.70?sql7=true"; // use your hostname and port number here
String login = "sa"; // use your login here
String password =""; // use your password here
public Connection connection = null;
public Statement st = null;
public ResultSet rs = null;
public sql_data(){
try {
Class.forName("com.inet.tds.TdsDriver").newInstance();
DriverManager.setLoginTimeout(10);
|
驱动我发到你邮箱中。然后在classpath中指定,必须指定到文件。
bean如下:
package mydb;
import java.sql.*;
public class dsql7 {
String sDBDriver = "com.inet.tds.TdsDriver";
String sConnStr = "jdbc:inetdae7:localhost:1433";
String sDataname= "";
Connection conn = null;
Statement stmt;
ResultSet rs = null;
public dsql7() {
try {
Class.forName(sDBDriver);
}
catch (java.lang.ClassNotFoundException e) {
System.err.println("mydb(): " + e.getMessage());
}
}
public void setdataname(String dataname) {
sDataname=dataname;
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,"sa","pjieyeah");
conn.setCatalog(sDataname);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"sa","pjieyeah");
conn.setCatalog(sDataname);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch (SQLException ex) {
System.err.println("ExecuteQuery: " + ex.getMessage());
}
}
public void close() {
try {
if (rs!=null)
{
rs.close();
}
stmt.close();
conn.close();
}
catch (SQLException ex) {
System.err.println("error");
}
}
}
bean如下:
package mydb;
import java.sql.*;
public class dsql7 {
String sDBDriver = "com.inet.tds.TdsDriver";
String sConnStr = "jdbc:inetdae7:localhost:1433";
String sDataname= "";
Connection conn = null;
Statement stmt;
ResultSet rs = null;
public dsql7() {
try {
Class.forName(sDBDriver);
}
catch (java.lang.ClassNotFoundException e) {
System.err.println("mydb(): " + e.getMessage());
}
}
public void setdataname(String dataname) {
sDataname=dataname;
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr,"sa","pjieyeah");
conn.setCatalog(sDataname);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
try {
conn = DriverManager.getConnection(sConnStr,"sa","pjieyeah");
conn.setCatalog(sDataname);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch (SQLException ex) {
System.err.println("ExecuteQuery: " + ex.getMessage());
}
}
public void close() {
try {
if (rs!=null)
{
rs.close();
}
stmt.close();
conn.close();
}
catch (SQLException ex) {
System.err.println("error");
}
}
}
|
http://www.csdn.net/expert/topic/85/85391.shtm
|
Tds就是Tabular Data Stream的缩写,它是Sql Server的数据通讯协议,最低层的。dblib/oledb等都是在它上面。所以TdsDrvier就是最好的Sql Server Driver了,没有更好的了。
|
看来是classpath没有设置好
你的驱动有没有?就是TdsDriver?
有的话把它加到classpath里面去
你的驱动有没有?就是TdsDriver?
有的话把它加到classpath里面去
|
死蠢,边个叫你拿TdsDriver,你
总会有个包架,比如乜XXX.jar,乜XX.zip
总会有个包架,比如乜XXX.jar,乜XX.zip
|
我点知你边个包,你想连接数据库
居然没有驱动程序,那怎么帮你...
居然没有驱动程序,那怎么帮你...
|
果然是见利忘义