首先,我使用的是NetBeans IDE + mysql5 + tomcat6.0
问题1:大家知道在JSP中插入java代码是用的<% %>这一对符号括起来的嘛,以前我用
code=Java]<%
System.out.print("111111");
%>[[/code]都可以在tomcat的控制台中打印出信息,以测试代码运行的结果!但是今天突然打印不出来了!
有没有哪位遇见过类似情况,知道如何解决的?请告诉下。问题2:Calendar c = Calendar.getInstance();
Date day1 = c.getTime();//今天的时间
c.add(Calendar.DATE, -7);//将日期减少7个单位
Date day2 = c.getTime();//7天前
String startT = Utility.formatDate(day2);//默认的起始时间
String endT = Utility.formatDate(day1);//默认的截止时间
System.out.print(startT);
System.out.print(endT);
pageContext.setAttribute("date1", startT);//赋值给网页
pageContext.setAttribute("date2", endT);//赋值给网页
在以上代码中,我使用setAttribute方法给date1和date2赋值,date1和date2是
<input class="Wdate" type="text" name="date1" id="startTime" onClick="WdatePicker()" style="width:90px;height:20px"/>
To:
<input class="Wdate" type="text" name="date2" id="endTime" onClick="WdatePicker()" style="width:90px;height:20px"/>中的属性名称。但是在网页上面不能显示出来,请问为什么?问题3:我在局域网内用另外一台电脑作为服务器,连接服务器上面的mysql数据库,为什么老是被报抛出异常,一种是
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
一种是java.net.ConnectException: Connection timed out: connect
我不知道为什么,而我写的JSP代码里面是有链接数据库并从中选出数据显示在网页上的功能,但是奇怪的是,同样的代码,同一个JSP,有时运行第一次时不行,再运行一次就行了,下一次又可能不行了!请问是不是服务器上面的mysql配置有问题啊?先谢谢各位不吝赐教的同志了 万分感谢,我是小白,麻烦说得详细,通俗点 啊!
问题1:大家知道在JSP中插入java代码是用的<% %>这一对符号括起来的嘛,以前我用
code=Java]<%
System.out.print("111111");
%>[[/code]都可以在tomcat的控制台中打印出信息,以测试代码运行的结果!但是今天突然打印不出来了!
有没有哪位遇见过类似情况,知道如何解决的?请告诉下。问题2:Calendar c = Calendar.getInstance();
Date day1 = c.getTime();//今天的时间
c.add(Calendar.DATE, -7);//将日期减少7个单位
Date day2 = c.getTime();//7天前
String startT = Utility.formatDate(day2);//默认的起始时间
String endT = Utility.formatDate(day1);//默认的截止时间
System.out.print(startT);
System.out.print(endT);
pageContext.setAttribute("date1", startT);//赋值给网页
pageContext.setAttribute("date2", endT);//赋值给网页
在以上代码中,我使用setAttribute方法给date1和date2赋值,date1和date2是
<input class="Wdate" type="text" name="date1" id="startTime" onClick="WdatePicker()" style="width:90px;height:20px"/>
To:
<input class="Wdate" type="text" name="date2" id="endTime" onClick="WdatePicker()" style="width:90px;height:20px"/>中的属性名称。但是在网页上面不能显示出来,请问为什么?问题3:我在局域网内用另外一台电脑作为服务器,连接服务器上面的mysql数据库,为什么老是被报抛出异常,一种是
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
一种是java.net.ConnectException: Connection timed out: connect
我不知道为什么,而我写的JSP代码里面是有链接数据库并从中选出数据显示在网页上的功能,但是奇怪的是,同样的代码,同一个JSP,有时运行第一次时不行,再运行一次就行了,下一次又可能不行了!请问是不是服务器上面的mysql配置有问题啊?先谢谢各位不吝赐教的同志了 万分感谢,我是小白,麻烦说得详细,通俗点 啊!
改成System.out.println("111111"); 打印出来了,你没看到。
我把数据库的链接做成了javabean
package javabean1;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
//import java.sql.ResultSet;
import java.sql.SQLException;
//import java.sql.Statement;public class DB_operation
{/**
* 取得一个数据库连接
* @return
* @throws SQLException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
*/
public Connection getConnection() throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
{
Connection conn = null;
//加载数据库驱动类
Class.forName("com.mysql.jdbc.Driver").newInstance();
//数据库连接URL
String url = "jdbc:mysql://192.168.1.240:3306/project_1";
//数据库用户名
String user = "root";
//数据库密码
String password = "1234";
//根据数据库参数取得一个数据库连接
conn = DriverManager.getConnection(url, user, password);
return conn;
}/**
* 根据传入的SQL语句返回一个结果集
* @param sql
* @return
* @throws Exception
*/
/*public Statement get_create_state_ment() throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
{
Connection conn = null;
Statement stmt = null;
conn = getConnection();
stmt = conn.createStatement();
return stmt;
}*//*public ResultSet select(String sql) throws Exception
{
Connection conn = null
Statement stmt = null;
ResultSet rs = null;
try
{
stmt = get_create_state_ment();
rs = stmt.executeQuery(sql);
return rs;
}catch(SQLException sqle)
{
throw new SQLException("select data exception: "+ sqle.getMessage());
}catch (Exception e)
{
throw new Exception("System e exception: " + e.getMessage());
}
}*/
/**
* 根据传入的SQL语句向数据库增加一条记录
* @param sql
* @throws Exception
*/
public void insert(String sql) throws Exception
{
Connection conn = null;
PreparedStatement ps = null;
try
{
conn = getConnection();
ps = conn.prepareStatement(sql);
ps.executeUpdate();
}catch(SQLException sqle)
{
throw new Exception("insert data exception: " + sqle.getMessage());
}finally
{
try
{
if (ps != null)
{
ps.close();
}
}catch (Exception e)
{
throw new Exception("ps close exception: " + e.getMessage());
}
}
try
{
if(conn != null)
{
conn.close();
}
}
catch (Exception e)
{
throw new Exception("connection close exception: " + e.getMessage());
}
}/**
* 根据传入的SQL语句更新数据库记录
* @param sql
* @throws Exception
*/
public void update(String sql) throws Exception
{
Connection conn = null;
PreparedStatement ps = null;
try
{
conn = getConnection();
ps = conn.prepareStatement(sql);
ps.executeUpdate();
}
catch (SQLException sqle)
{
throw new Exception("update exception: " + sqle.getMessage());
}
finally
{
try
{
if (ps != null)
{
ps.close();
}
}
catch (Exception e)
{
throw new Exception("ps close exception: " + e.getMessage());
}
}
try
{
if (conn != null)
{
conn.close();
}
}
catch (Exception e)
{
throw new Exception("connection close exception: " + e.getMessage());
}
}/**
* 根据传入的SQL语句删除一条数据库记录
* @param sql
* @throws Exception
*/
public void delete(String sql) throws Exception
{
Connection conn = null;
PreparedStatement ps = null;
try
{
conn = getConnection();
ps = conn.prepareStatement(sql);
ps.executeUpdate();
}
catch (SQLException sqle)
{
throw new Exception("delete data exception: " + sqle.getMessage());
}
finally
{
try
{
if (ps != null)
{
ps.close();
}
}
catch (Exception e)
{
throw new Exception("ps close exception: " + e.getMessage());
}
}
try
{
if (conn != null)
{
conn.close();
}
}
catch (Exception e)
{
throw new Exception("connection close exception: " + e.getMessage());
}
}
}
然后我每次连接数据库就用的是以下代码Connection con = db.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);处理结果集和关闭对象就省略了哈。我昨天用这个都能正常连接的啊!
您是说控制台一出来就消失了那种情况吗?
我不是的,我用的NetBeans IDE,它提供一个tomcat控制台信息的窗口,我以前都是用System.out.print直接打印信息的,但是今天突然打不起了!况且我试了试您说的System.out.println,也不得行啊!