import java.sql.*;
public class DataBaseOperation
{
private Connection connection;
public DataBaseOperation(String driver,String url,String user,String password) throws ClassNotFoundException,SQLException
{
this.connection=null;
Class.forName(driver);
this.connection=DriverManager.getConnection(url,user,password);
}
public DataBaseOperation(String driver,String url) throws ClassNotFoundException,SQLException
{
this.connection=null;
Class.forName(driver);
this.connection=DriverManager.getConnection(url);
}
public void finalize()throws SQLException
{
this.connection.close();
}
public String getDBAbout()throws SQLException
{
String message="";
DatabaseMetaData dbmd=this.connection.getMetaData();
message="JDBC驱动程序:"+dbmd.getDriverName()+" "+dbmd.getDriverVersion()+"\r\n"+
"JDBC URL:"+dbmd.getURL()+"\r\n"+
"数据库:"+dbmd.getDatabaseProductName()+"\r\n"+
"数据库版本:"+dbmd.getDatabaseMajorVersion()+"\r\n"+
"用户名:"+dbmd.getUserName()+"\r\n";
return message;
}
}
class GetDBMessage
{
public static void main(String[] args)
{
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL";
String user="wy";
String password="";
try
{
DataBaseOperation dboper=new DataBaseOperation(driver,url,user,password);
System.out.println(dboper.getDBAbout());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
出现连接错误:
java.sql.SQLException: No suitable driver found for jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at DataBaseOperation.<init>(DataBaseOperation.java:9)
at GetDBMessage.main(DataBaseOperation.java:43)
public class DataBaseOperation
{
private Connection connection;
public DataBaseOperation(String driver,String url,String user,String password) throws ClassNotFoundException,SQLException
{
this.connection=null;
Class.forName(driver);
this.connection=DriverManager.getConnection(url,user,password);
}
public DataBaseOperation(String driver,String url) throws ClassNotFoundException,SQLException
{
this.connection=null;
Class.forName(driver);
this.connection=DriverManager.getConnection(url);
}
public void finalize()throws SQLException
{
this.connection.close();
}
public String getDBAbout()throws SQLException
{
String message="";
DatabaseMetaData dbmd=this.connection.getMetaData();
message="JDBC驱动程序:"+dbmd.getDriverName()+" "+dbmd.getDriverVersion()+"\r\n"+
"JDBC URL:"+dbmd.getURL()+"\r\n"+
"数据库:"+dbmd.getDatabaseProductName()+"\r\n"+
"数据库版本:"+dbmd.getDatabaseMajorVersion()+"\r\n"+
"用户名:"+dbmd.getUserName()+"\r\n";
return message;
}
}
class GetDBMessage
{
public static void main(String[] args)
{
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL";
String user="wy";
String password="";
try
{
DataBaseOperation dboper=new DataBaseOperation(driver,url,user,password);
System.out.println(dboper.getDBAbout());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
出现连接错误:
java.sql.SQLException: No suitable driver found for jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at DataBaseOperation.<init>(DataBaseOperation.java:9)
at GetDBMessage.main(DataBaseOperation.java:43)
String url="jdbc:sqlserver://localhost:1433;DatabaseName=JWGL";
String user="wy";
String password="";
import java.sql.*;
import com.sun.rowset.CachedRowSetImpl;
public class DB {
Statement stmt;
String mc;
Connection conn = null;
CachedRowSetImpl crs;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=king";
//king为你的数据库的名称
String user="sa";
String password="";
public void setURL(String str){//用于修改所连数据库的名字
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName="+str+"";
}
public CachedRowSetImpl dbquery(String sqlstr){//查询数据库时调用此方法
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn= DriverManager.getConnection(url,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
crs=new CachedRowSetImpl();
ResultSet rs=stmt.executeQuery(sqlstr);
crs.populate(rs);
if(rs!=null)
{
rs.close();
stmt.close();
rs=null;
stmt=null;
}
conn.close();
}catch(Exception e)
{
System.out.println("s4:"+e.toString());
//e.printStackTrace();
}
return crs;
}
public void dbexe(String sqlstr){//查询、删除、修改调用这个方法
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn= DriverManager.getConnection(url,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//System.out.println("--------------ggggrr-----------"+sqlstr);
stmt.execute(sqlstr);
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
希望能给你点帮助或灵感,呵呵!!!
{
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL";
String user="wy";
String password="";
try
{
DataBaseOperation dboper=new DataBaseOperation(driver,url,user,password);
System.out.println(dboper.getDBAbout());
}
catch(Exception e)
{
e.printStackTrace();
}
} 其中这一句出现问题了吧String url="jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL";
应该是String url="jdbc:sqlserver://localhost:1433;DatabaseName=JWGL"; 试试吧
Sql 2000打补丁3 补丁4,装MS提供的jdbc2000驱动。
你肯定没导入驱动
如果你在eclipse下,那在addExtenalJar包,就行了
在JCREATOR 或者直接写JAVA文件下就需要在系统环境变量中导入包名 路径
java.sql.SQLException: No suitable driver found for jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at DataBaseOperation. <init>(DataBaseOperation.java:9)
at GetDBMessage.main(DataBaseOperation.java:43)
一看不就是驱动问题啊,还有URL有问题
jdbc:mircosoft:sqlserver://localhost:1433;DatabaseName=JWGL
有拼写错误microsoft
microsoft拼写错误
正确Microsoft
正确Microsoft楼上的兄弟佩服,眼力好呀