@
smallerror 我是这样做的…… 然后在同一级目录下的.java文件,
Entry.java:
//File: entry.java
//Desc: Entry Model
package com.moment.utils;
import java.sql.*;
public class Entry
{
private String content;
private int sender_id;
private boolean visible;
private int id;
Entry(String c,int sid)
{
this.content=c;
this.sender_id=sid;
}
int add()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/S2013150080?useUnicode=true&characterEncoding=utf-8","S2013150080","091330");
String sql = "INSERT INTO Entry (Content,Sender_id) values (?,?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,this.content);
ps.setInt(2,this.sender_id);
int i = ps.executeUpdate();
ps.close();
conn.close();
return i;
}
catch (Exception e)
{
return 0;
}
}
}
index.jsp:
<%@ page language="java" import="java.util.*,com.moment.utils.Entry;" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%
Entry e = new Entry("Heel",1);
out.print(e.add());
%>
可是这样子会报错:Only a type can be imported. com.moment.utils.Entry resolves to a package