但是我在命令行里进行测试时出现以下问题.请问这该如何解决?
另外,我在Deamweaver中用JSP通过JDBC和SQL2000连接时出现以下问题,
[Microsoft][SQLServer 2000 Driver for JDBC]Unsupported VM encoding MS936
这个又如何解决呢?
这是代码:
// Java Document
import java.sql.*;
public class DBTest {
Connection con;
Statement sta;
String driver;
String url;
String user;
String pwd;
ResultSet rs=null;
public DBTest(){
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName =pubs";
user= "sa";
pwd= "1";
init();
}
public void init()
{
try{
Class.forName(driver);
System.out.println("driver is ok");
con = DriverManager.getConnection(url,user,pwd);
System.out.println(con);
System.out.println("conection is ok");
sta = con.createStatement();
System.out.println(sta);
System.out.println("createStatement is ok");
rs=sta.executeQuery("select * from admintable");
while(rs.next())
System.out.println(rs.getInt("username"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
new DBTest();
}
}
如果 只安装JRE150,那么我的"系统变量"该如何设置呢?
可不可以只安装J2SDK.我目前的系统设置是这样的:
Tomcat5.5安装在C:\Tomcat 5.5
Tomcat 5.5安装时从"JRE150"里寻找虚拟机.
JDBC安装在C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC
j2sdk1.4.2_10安装在C:\j2sdk1.4.2_10
JDBC里3个jar放到C:\Tomcat 5.5\common\lib里
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
以下是系统环境变量设置:
★★★★★★★★★★★★
JAVA_HOME=C:\j2sdk1.4.2_10
CATALINA_HOME=c:\tomcat 5.5
CATALINA_BASE=c:\tomcat 5.5
path=
%JAVA_HOME%\bin;
%path%;
%systemroot%\system32;
%systemroot%;
%systemroot%\system32\wbem;
c:\program files\microsoft sql server\80\tools\binn;
F:\Matlab7.1\bin\win32;
classpath=
.;%JAVA_HOME%\bin;
%JAVA_HOME%\lib;
%JAVA_HOME%\lib\dt.jar;
%JAVA_HOME%\lib\tools.jar;
%JAVA_HOME%\common\lib\servlet-api.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
我把j2sdk1.4.2_10删除后,将jre1.5.0_02安装在C:\Program Files\Java\jre1.5.0_02\lib
由于jre1.5.0_02中并没有dt.jar,tools.jar,servlet-api.jar,三个文件,因此我将classpath换成
classpath=
.;%JAVA_HOME%\bin;
%JAVA_HOME%\lib;
%JAVA_HOME%\jre\lib\rt.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
之后在命令行里,测试以下内容:
public class Test{
public static void main(String args[]){
System.out.println("This is a test program.");
}
}
没有成功.