國產處理器伺服器上搭建mysql(MariaDB)+jsp(java)開發平臺,基於海之舟1.0A作業系統

wxh585發表於2019-10-25

1.mysql設定

對於海之舟1.0A作業系統,mysql、java、tomcat已預裝,在/etc/rc.local中設定開機啟動即可。

su root

nano /etc/mysql/mariadb.conf.d/50-server.cnf

#bind-address           = 127.0.0.1     //註釋這行,關閉ip限制.

mysql -v  //進入資料庫

>use mysql;

>CREATE DATABASE db1; 

>SHOW DATABASES;

>grant all on *.* to zs1@'%' identified by '1234';

>show grants for zs@'%';

>use db1;

> CREATE TABLE t1(bid int(20) not null auto_increment primary key, id int(100),xm varchar(20),zh varchar(100),uploadTime varchar(100));

>SHOW TABLES;

> DESCRIBE t2;  //檢視錶t2的結構

> insert into t1(id,xm,zh) values (20,"zhangs","myzh");

2.jsp

su zs

cd /home/zs/apache-tomcat-8.5.35/webapps/ROOT

nano m1.jsp  //已預置的範例程式碼

<%@ page contentType="text/html;charset=UTF-8"%>

<%@ page import="java.sql.*"%>

<html>

<head>

<%

  response.setContentType("text/html;charset=UTF-8");

  request.setCharacterEncoding("UTF-8");

%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<%

  Class.forName("com.mysql.cj.jdbc.Driver").newInstance();

  Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "zs1", "1234");

  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

      ResultSet.CONCUR_UPDATABLE);

  String  id=request.getParameter("id");

  String sql="select * from t1 order by bid";

  ResultSet rs=stmt.executeQuery(sql);

  out.print("<br>sql:"+sql);

  out.print("<br>bid-----id-----xm-----zh");

  while(rs.next())

  {

    out.print("<br>&nbsp;&nbsp;"+rs.getInt(1));

    out.print("&nbsp;&nbsp;&nbsp;&nbsp;"+rs.getString(2));

    out.print("&nbsp;&nbsp;&nbsp;&nbsp;"+rs.getString(3));

    out.print("&nbsp;&nbsp;&nbsp;&nbsp;"+rs.getString(4));

  }

  //c=Integer.parseInt(ss);

    rs.close();

    stmt.close();

    conn.close();

%>

</body>

</html>

在流覽器中開啟192.168.1.125:8080/m1.jsp即可

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23102655/viewspace-2661388/,如需轉載,請註明出處,否則將追究法律責任。

相關文章