200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > linux jsp mysql_Linux JSP连接MySQL数据库

linux jsp mysql_Linux JSP连接MySQL数据库

时间:2024-06-08 18:28:38

相关推荐

linux jsp mysql_Linux JSP连接MySQL数据库

Linux(Ubuntu平台)JSP通过JDBC连接MySQL数据库,与Windows平台类似,步骤如下:

解压jdbc:tar-zxvfmysql-connector-java-5.1.18.tar.gz

配置jdbc:cpmysql-connector-java-5.1.18-bin.jar

/usr/local/jdk1.6.0_22/jre/lib/ext/

JSP示例:

Read from mySQL Database

Following records are selected from table "gametop800"

String DRIVER = "com.mysql.jdbc.Driver";

String url = "jdbc:mysql://localhost:3306/top800";

Connection con = null;

ResultSet rst = null;

Statement stmt = null;

int i = 1;

try {

Class.forName(DRIVER).newInstance();

con = DriverManager.getConnection(url, "root", "");

stmt = con.createStatement();

rst = stmt.executeQuery("select top, id, name, country, dtime from gametop800 where top=1");

while (rst.next()) {

if (0 == i%2) {

%>

.

%>

.

i++;

}

rst.close();

stmt.close();

con.close();

} catch (Exception e) {

System.out.println(e.getMessage());

}

%>

执行结果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。