jdbc的问题 代码放上看看sqlserver的jdbc好像才是出问题,HEHE 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.将Msbase.jar,mssqlserver.jar,msutil.jar 三个文件拷贝到JDK的安装目录下。没有这些文件可以到官方网站下载www.microsoft.com2.在代码中就可以连了。 Connection con; Statement stmt; ResultSet rst; Database database1 = new Database(); Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); con = DriverManager.getConnection"jdbc:microsoft:sqlserver://132.147.180.5:1433;DatabaseName=opt20", "sa", "confirm2"); database1.setJdbcConnection(con); 去试试吧。 将Msbase.jar,mssqlserver.jar,msutil.jar 三个文件拷贝到JDK的安装目录下,这一步我早做了,我的同一个程序在windows 2000 server就好使呀,代码是这样的:// Test MSSQL_DataBase import java.sql.*;import java.sql.SQLException;import java.lang.ClassNotFoundException;import sun.jdbc.odbc.JdbcOdbcDriver;import com.microsoft.jdbc.sqlserver.SQLServerDriver;public class TestDB_Temp { //define Connection connection; Statement statement; ResultSet resultset; ResultSetMetaData md; //odbc //String drive="sun.jdbc.odbc.JdbcOdbcDriver"; //String url="jdbc:odbc:MyDataBase"; //jdbc String drive="com.microsoft.jdbc.sqlserver.SQLServerDriver"; String url="jdbc:microsoft:sqlserver://DAGANG:1433;DatabaseName=MyDataBase"; String user="sa"; String password="dagang"; String sql="select * from User_TB"; int i; String a,b,c,d,e; public TestDB_Temp(){ try { Class.forName(drive).newInstance(); } catch (ClassNotFoundException cex) { System.out.println ("Not fond drive\n"+cex); } catch(Exception e){ System.out.println ("Error..."+e); } findSQL(); } //Find SQL public void findSQL(){ try { connection=DriverManager.getConnection(url,user,password); statement=connection.createStatement(); resultset=statement.executeQuery(sql); md=resultset.getMetaData(); while(resultset.next()){ i=resultset.getInt(1); a=resultset.getString(2); b=resultset.getString(3); c=resultset.getString(4); d=resultset.getString(5); e=resultset.getString(6); printResult(); } close(); } catch(SQLException sqle){ System.out.println ("not find...."+sqle); } catch (Exception ex) { System.out.println ("error...."+ex); } } //print Resultset public void printResult()throws Exception{ for(int j=1;j<7;j++){ System.out.print(md.getColumnName(j)+"\t"); } System.out.print("\n"+i+"\t"); System.out.print(a+"\t"); System.out.print(b+"\t"); System.out.print(c+"\t"); System.out.print(d+"\t"); System.out.println (e); } // close DB public void close()throws Exception{ resultset.close(); statement.close(); connection.close(); } // public static void main(String[] args){ new TestDB_Temp(); } } Exception in thread "main" java.lang.NullPointerException 为什么内部类只能访问外部类中的 final型的常量 隆重推出一套书,能有免费培训的!!! Java中TextArea如何完美实现剪切和粘贴? servlet如何引用jdbc需要的驱动包 非常简单的问题 学习java的方法??各位高手指教! htmlconvernter怎么用? 如何对记事本中的java程序进行编译和执行? java 与sql server的连接2 QQ上的java群,欢迎加入!~ Java读取Oracle数据时的中文问题,现场实施中,特急,在线等待...
2.在代码中就可以连了。
Connection con;
Statement stmt;
ResultSet rst; Database database1 = new Database();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
con = DriverManager.getConnection"jdbc:microsoft:sqlserver://132.147.180.5:1433;DatabaseName=opt20", "sa", "confirm2");
database1.setJdbcConnection(con);
去试试吧。
// Test MSSQL_DataBase import java.sql.*;
import java.sql.SQLException;
import java.lang.ClassNotFoundException;
import sun.jdbc.odbc.JdbcOdbcDriver;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;public class TestDB_Temp {
//define
Connection connection;
Statement statement;
ResultSet resultset;
ResultSetMetaData md;
//odbc
//String drive="sun.jdbc.odbc.JdbcOdbcDriver";
//String url="jdbc:odbc:MyDataBase";
//jdbc
String drive="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://DAGANG:1433;DatabaseName=MyDataBase";
String user="sa";
String password="dagang";
String sql="select * from User_TB";
int i;
String a,b,c,d,e; public TestDB_Temp(){
try {
Class.forName(drive).newInstance();
}
catch (ClassNotFoundException cex) {
System.out.println ("Not fond drive\n"+cex);
}
catch(Exception e){
System.out.println ("Error..."+e);
}
findSQL();
}
//Find SQL
public void findSQL(){
try {
connection=DriverManager.getConnection(url,user,password);
statement=connection.createStatement();
resultset=statement.executeQuery(sql);
md=resultset.getMetaData();
while(resultset.next()){
i=resultset.getInt(1);
a=resultset.getString(2);
b=resultset.getString(3);
c=resultset.getString(4);
d=resultset.getString(5);
e=resultset.getString(6);
printResult();
}
close();
}
catch(SQLException sqle){
System.out.println ("not find...."+sqle);
}
catch (Exception ex) {
System.out.println ("error...."+ex);
}
}
//print Resultset
public void printResult()throws Exception{
for(int j=1;j<7;j++){
System.out.print(md.getColumnName(j)+"\t");
}
System.out.print("\n"+i+"\t");
System.out.print(a+"\t");
System.out.print(b+"\t");
System.out.print(c+"\t");
System.out.print(d+"\t");
System.out.println (e);
}
// close DB
public void close()throws Exception{
resultset.close();
statement.close();
connection.close();
}
//
public static void main(String[] args){
new TestDB_Temp();
}
}