51,410
社区成员
发帖
与我相关
我的任务
分享
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class show_pathway extends HttpServlet {
public void service(HttpServletRequest request,
HttpServletResponse response) throws IOException
{
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String org_name = request.getParameter("org_name");
out.println(org_name);
String mapno = request.getParameter("mapno");
out.println(mapno);
}
}
import java.sql.*;
public class JDBCTest {
public static void main(String[] args){
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/scutcs";
String user = "root";
String password = "";
System.out.println("执行结果如下所示:");
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
System.out.println("Succeeded connecting to the Database!");
Statement statement = conn.createStatement();
String sql = "select * from student";
ResultSet rs = statement.executeQuery(sql);
System.out.println("-----------------");
System.out.println("执行结果如下所示:");
System.out.println("-----------------");
System.out.println(" 学号" + "\t" + " 姓名");
System.out.println("-----------------");
String name = null;
while(rs.next()) {
name = rs.getString("sname");
name = new String(name.getBytes("ISO-8859-1"),"GB2312");
System.out.println(rs.getString("sno") + "\t" + name);
}
rs.close();
conn.close();
} catch(ClassNotFoundException e) {
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}