java常见错误云集与注意事项

时间:2024-01-08 22:55:08

1.安装Eclipse时,尽量jdk不要用jre,jdk包含jre j

JDK就是Java Development Kit.简单的说JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环境。SDK是Software Development Kit 一般指软件开发包,可以包括函数库、编译程序等。
JRE是Java Runtime Enviroment是指Java的运行环境,是面向Java程序的使用者,而不是开发者。

详情可见:http://www.cnblogs.com/myitm/archive/2011/05/03/2035942.html

使用sun.misc.BASE64Decoder出错解决方案

Access restriction: The type BASE64Decoder is not accessible due to restriction on required library D:\java\jre1.5.0_08\lib\rt.jar

在网上找到了解决方法如下,我是用第二种方法解决的~~ 
Solution 1 :

import=”sun.misc.BASE64Decoder” 
出现错误提示为:Access restriction: The type BASE64Decoder is not accessible due to restriction 
on required library D:\ProgramFiles\MyEclipse\jre\lib\rt.jar 
Solution 1 : 
BASE64Decoder 
这个没有java doc,属于jdk里不推荐使用的工具类 
解决方案: 
使用apache common中的Base64替换 
你可以在这里下载Apache commons codec: 
http://commons.apache.org/codec/ 
替换一下就可以了 
强烈建议不要用sun.misc,是不安全的 ,最好不要使用

Solution 2: 其实就是删掉jre包,从新导入一下
1. Open project properties. 
2. Select Java Build Path node. 
3. Select Libraries tab. 
4. Remove JRE System Library. 
5. Add Library JRE System Library. 

Problems while loading database driverclass (com.microsoft.jdbc.sqlserver.SQLServerDriver)
用hiberatetools打开表时出现的错误,怎么也查不出来
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="sqlserver">
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.password">sa123</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://10.16.102.16\CLEANIDSVC_DB:1433;DatabaseName=CleanID_DB2</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
</session-factory>
</hibernate-configuration>

其实就是默认驱动是:

com.microsoft.jdbc.sqlserver.SQLServerDriver

把jdbc与sqlser调过来变成这样:
com.microsoft.sqlserver.jdbc.SQLServerDriver
在sqljdbc4.jar中修改了。

Html:
<base target="_self">
在jsp页面头部加可以控制页面在自身打开,不会跳转到新页面

java连接sql2005出错误

fail to load JDBC/ODBC driver
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 127.0.0.1, port 1433 has failed. Error: Connection refused: connect. Please verify the connection properties and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.

现在的一般方式连接数据库已经不启用1433端口了,是以直接ip连接实例的方式,但是一些老的程序还是会以指定端口方式访问数据库,比如 java

<alias>ntpa</alias>
   <driver-url>jdbc:sqlserver://localhost:1433;DatabaseName=aa</driver-url>
  <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
  <driver-properties>
   <property name="user" value="sa" />
   <property name="password" value="123" />
  </driver-properties>

在mssql默认1433端口是不打开的,要你手动开启动态ip,解决方式就是设置全局动态端口为0

SQL Server Configuration Manager-SQL Server 2005网络配置-MSSQLSERVER的协议-TCP/IP-属性-ip地坛-IPAll-TCP动态端口为0,然后重启服务

(控制面板\系统和安全\管理工具\服务\SQLSERVER(MSSQLSERVER)重启),这样就解决了

sql乱码:

配置一下eclipse,utf-8编码,tomcat在servlet.xml  配置一下编码格式utf-8  一般就没有问题了

如果不想配置的话,如果在jsp传到action不传对象而传的参数是中文的话,会出现乱码,直接读出编码,转一下就可以了

if(buyway!=null)
{
buyway=new String(buyway.getBytes("ISO8859-1"),"UTF-8");
}