K
KervenLee
Unregistered / Unconfirmed
GUEST, unregistred user!
出错提示为
Exception in thread "main"java.lang.NoClassDefUndError:com/microsoft/util/UtilDummyPrintWriter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(class.java:120)
at Selector.main(Selector.java:20)
我的代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
public class Selector
{
public static void main(String[] args)
{
String url = "jdbc:microsoft:sqlserver://kevin:1433;DataBaseName=Northwind";
Connection con = null;
try
{
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(driver).newInstance();
}
catch (Exception e)
{
System.out.println("Failed to load Microsoft SQL Server 2000 Driver.");
e.printStackTrace();
return;
}
try
{
con = DriverManager.getConnection(url,"sa","");
Statement select = con.createStatement();
ResultSet result = select.executeQuery("SELECT FirstName,LastName from Employees");
System.out.println("Got results : ");
while(result.next())
{
String firstName;
String lastName;
firstName = result.getString(1);
lastName = result.getString(2);
if(result.wasNull())
{
return;
}
System.out.println("FirstName = "+firstName);
System.out.println("LastName = "+lastName);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (con != null)
{
try
{
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}
Exception in thread "main"java.lang.NoClassDefUndError:com/microsoft/util/UtilDummyPrintWriter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(class.java:120)
at Selector.main(Selector.java:20)
我的代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
public class Selector
{
public static void main(String[] args)
{
String url = "jdbc:microsoft:sqlserver://kevin:1433;DataBaseName=Northwind";
Connection con = null;
try
{
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(driver).newInstance();
}
catch (Exception e)
{
System.out.println("Failed to load Microsoft SQL Server 2000 Driver.");
e.printStackTrace();
return;
}
try
{
con = DriverManager.getConnection(url,"sa","");
Statement select = con.createStatement();
ResultSet result = select.executeQuery("SELECT FirstName,LastName from Employees");
System.out.println("Got results : ");
while(result.next())
{
String firstName;
String lastName;
firstName = result.getString(1);
lastName = result.getString(2);
if(result.wasNull())
{
return;
}
System.out.println("FirstName = "+firstName);
System.out.println("LastName = "+lastName);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if (con != null)
{
try
{
con.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}