提示:一定要保证电脑处于联网状态

我们要下载一个mysql-connector-java-5.0.8-bin.jar的东西(当然这个jar包的版本号和你的mysql版本号的关系不是非常大),放到你新建的dynamic
project下的WebContent文件夹下的WEB-INF下的lib。让这个Web工程可以连接Mysql数据库。官网http://dev.mysql.com/downloads/connector/j/5.0.html

之后在project中的javaresources下的src文件夹新建一个classdb_test.java(详细内容见附件)

右键runas-> java application,看是否已经ok了

假设ok的话,在webcontent文件夹下新建jspfile
index.jsp(详细内容见附件)

右键project->runas ->run on server

应该能够在浏览器中看到你的内容了。假设报错,能够多尝试下几遍,可能是哪个环节出现了什么问题。

也可能是版本号不一致导致的,所以须要你多试几次。

内容可參考

http://www.2cto.com/os/201504/392308.html

db_test.java

importjava.sql.*;

publicclassdb_test{

publicstaticvoidmain(String[]
srg){

try{

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

}catch(InstantiationException
| IllegalAccessException

|ClassNotFoundException e) {

//TODOAuto-generated
catch block

e.printStackTrace();

}

Connection
conn = null;

try{

conn=DriverManager.getConnection("jdbc:mysql://localhost/mysql1","root","wtt561111");

}catch(SQLException
e) {

//TODOAuto-generated
catch block

e.printStackTrace();

}

Statement
stmt = null;

try{

stmt= conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

}catch(SQLException
e) {

//TODOAuto-generated
catch block

e.printStackTrace();

}

String sql
= "select* from student";

try{

ResultSetrs = stmt.executeQuery(sql);

while(rs.next()){

Stringsno=rs.getString(2);

System.out.println(sno);

}

}catch(SQLException
e) {

//TODOAuto-generated
catch block

e.printStackTrace();

}

}

}

index.jsp

<%@pagecontentType="text/html;charset=gb2312"%>

<%@pageimport="java.sql.*"%>

<html>

<body>

<%

try{

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

}catch(Exception
e) {

//TODO
Auto-generated catch block

e.printStackTrace();

}

Connection
conn = null;

try{

conn=DriverManager.getConnection("jdbc:mysql://localhost/mysql1","root","wtt561111");

}catch(SQLException
e) {

//TODO
Auto-generated catch block

e.printStackTrace();

}

try{

if(conn.equals(null))

{out.println("nullerror");}

else{

//stmt=
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

Statementstmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

Stringsql
= "select* from student";

ResultSetrs = stmt.executeQuery(sql);

while(rs.next()){

Stringsno=rs.getString(1);

out.println(sno);

}

}

}catch(SQLException
e) {

//TODO
Auto-generated catch block

e.printStackTrace();

}

%>

</body>

</html>

ubuntu下eclipse连接mysql的更多相关文章

  1. Ubuntu 16.04LTS下eclipse连接mysql

    第一部分:打开eclipse,新建一个web工程,新建一个类db_test.java(jdbc连接mysql的原理自行百度) import java.sql.*; public class db_te ...

  2. ubuntu下C++连接mysql数据库

    参考了该博客的做法:http://zhmy.michael.blog.163.com/blog/static/861578792012101244715692/ 1.安装mysql: sudo apt ...

  3. ubuntu下python连接mysql

    apt-get install python-mysqldb

  4. (转) Eclipse连接MySQL数据库(傻瓜篇)

    Eclipse连接MySQL数据库(傻瓜篇) 原帖地址: http://www.cnblogs.com/fnng/archive/2011/07/18/2110023.html Posted on 2 ...

  5. Ubuntu下Eclipse中文乱码问题解决(转)

    Ubuntu下Eclipse中文乱码问题解决 把Windows下的工程导入到了Linux下Eclipse中,由于以前的工程代码,都是GBK编码的(Windows下的Eclipse 默认会去读取系统的编 ...

  6. Ubuntu下ssh连接在服务端显示图形界面

    Ubuntu下ssh连接在服务端显示图形界面 step1 安装ssh服务 服务端安装运行ssh,在终端运行命令如下: sudo apt-get install openssh-server 在客户端安 ...

  7. ubuntu下USB连接Android手机

    初始工作:将Android手机通过usb连接到电脑,之后点击VM-Removable Devices-google Android - Connect,即可. 若通过usb连接到电脑,Removabl ...

  8. Eclipse 连接MySql数据库总结

    Eclipse 连接MySql数据库总结 一.在MySql中创建数据库,并创建表,向表中插入数据 1.创建数据库 create database select_test 2.创建表 create ta ...

  9. c/c++使用VS2013连接MySQL与ubuntu下c链接mysql

    vs连接数据库事实上就是将mysql数据库.h头文件接口.lib链接文件和dll运行文件增加到项目中.以下是配置怎样增加. 转于http://www.cnblogs.com/justinzhang/a ...

随机推荐

  1. Windows开发小问题集

    ON_BN_KILLFOCUS无效,因为需要BS_NOTIFY

  2. linux使用mount命令挂载、umount命令取消挂载

    一.mount挂载目录方式: mount 挂载目录 磁盘目录 二.umout取消挂载目录方式: 1.umout 磁盘目录 2.umout 挂载目录 3.umout 磁盘目录 挂载目录 如下图

  3. 【PL/SQL】九九乘法口诀表

    --输出屏幕信息 SET serveroutput ON; --打印口诀表 DECLARE V_NUMBER1 ); --外层循环变量 V_NUMBER2 ); --内层循环变量 BEGIN .. - ...

  4. dotnetnuke 7.x登录时不跳到站点设置中的指定页

    查源码发现登录按钮有参数,点击跳到登录页或者弹窗登录,真正登录后会根据传参的url反回.因为皮肤对像没有相应参数,所以只能去掉参数.我是用js去的,偷个懒吧.如下所示: <script type ...

  5. C# 配置文件ini操作类

    // [ DllImport ( "kernel32" ) ] //private static extern long WritePrivateProfileString ( s ...

  6. Windows Server 2008无法远程连接

    Server 2008 R2依次配置好之后,重启发现总是远程桌面时而连接不上.具体现象如下: 偶尔可以通过桌面远程连接连接到Server.以为是防火墙的问题,各种设置——甚至关闭,依然无法连接.反复重 ...

  7. Redis 之持久化(rdb、aof)

    Redis的持久化有2种方式   1快照  2是日志 测试aof:

  8. 写一个 sum方法,在使用下面任一语法调用时,都可以正常工作

    console.log(sum(2,3)); // Outputs 5 console.log(sum(2)(3)); // Outputs 5 (至少)有两种方法可以做到: 方法1: functio ...

  9. 用jquery-easyui的布局layout写后台管理页面

    先在官网下载easyui文档 引入头部文件 <link rel="stylesheet" type="text/css" href="${pag ...

  10. tomcat 编码设置

    在Tomcat8.0之前的版本,如果你要向服务器提交中文是需要转码的(如果你没有修改server.xml中的默认编码),因为8.0之前Tomcat的默认编码为ISO8859-1. POST方式提交 r ...