eclipse如何连接mysql

eclipse如何连接mysqleclipse如何连接mysqleclipse如何连接mysqleclipse如何连接mysqleclipse如何连接mysqleclipse如何连接mysqleclipse如何连接mysql

6个回答

建立一个hibernate的配置表

  1. 首先安装mysql数据库,具体安装方法可以上百度搜下,也可以按照下面的方法来安装mysql:
    安装Mysql:
    下载xampp,安装;
    打开xampp 控制面板,启动mysql
    把Mysql的执行文件路径添加到PATH环境变量中来
    Mysql安装完成

  2. 下载mysql的连接jar包:mysql-connector-java-5.1.22-bin.jar;

  3. 启动......
    答案就在这里:eclipse连接mysql
    ----------------------Hi,地球人,我是问答机器人小S,上面的内容就是我狂拽酷炫叼炸天的答案,除了赞同,你还有别的选择吗?

首先引入mysql-connector-java-5.1.37.jar这个jar包,然后下面代码就可以连接了:

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

Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "");

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("select * from user");

下面这个方法就是连接MySQL数据库,当然你需要引入相应的包,import中所要引入的包即可,如3楼所说。

package com.icss.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**

  • @author Ф
    *
    */
    public class BaseDao {

    protected Connection conn;

    protected void openconnection() throws ClassNotFoundException,SQLException{ //主要是这个方法,其他的不用看
    try {
    if( conn == null || conn.isClosed() ){
    Class.forName("com.mysql.jdbc.Driver");

    conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/table","root","123456");//对应的是IP--用户名--密码
    }

    } catch (ClassNotFoundException e) {
    throw e;
    } catch (SQLException e) {

    throw e;
    }
    }

    public void closeResource(){

    if(conn != null){
        try {
            conn.close();
            conn = null;
        } catch (Exception e) {
            e.printStackTrace();
        }           
    }       
    

    }

    public void beginTransaction() throws Exception{
    this.openconnection();
    if(conn != null){
    conn.setAutoCommit(false);
    }

    }

    public void commit() throws Exception{
    if(conn != null){
    conn.commit();
    }

    }

    public void rollback() throws Exception{
    if(conn != null){
    conn.rollback();
    }

    }
    }

    如何使用这个方法?
    package com.icss.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.icss.service.dto.OrderFlow;

public class FlowDao extends BaseDao{

public List<OrderFlow> getFlowInfo(String orderid) throws Exception{

    List<OrderFlow> flows = null; 

    String sql="select o.state,o.orderinfo,o.uname,o.orderid,f.flowinfo " +
               " from tflow f,torder o  where o.orderid = f.orderid and o.orderid=?";//这里是sql语句,你随便
    this.openconnection();
    PreparedStatement ps = this.conn.prepareStatement(sql);
    ps.setString(1, orderid);
    ResultSet rs = ps.executeQuery();//这里是执行sql语句,并把结果返回给rs这个对象,其中resultset是sql包自带的类,不要担心
    if(rs != null){//下面的代码是告诉你如何取出来刚才查到的数据
        flows = new ArrayList<OrderFlow>();
        while(rs.next()){
            OrderFlow flow = new OrderFlow();
            flow.setFlowinfo(rs.getString("flowinfo"));
            flow.setOrderid(rs.getString("orderid"));
            flow.setOrderinfo(rs.getString("orderinfo"));
            flow.setUname(rs.getString("uname"));
            flows.add(flow);
        }
    }

    return flows;

} 

}

注:如果你觉得封装成方法比较麻烦,你完全可以把上面主要的代码拿过来全部写到main函数中也行,相比而言前者可能更加面向对象,更加灵活,想必你也知道。ok,就这些。

    String sql="select o.state,o.orderinfo,o.uname,o.orderid,f.flowinfo " +
    " from tflow f,torder o  where o.orderid = f.orderid and o.orderid=?";//这里是sql语句,你随便写
    Class.forName("com.mysql.jdbc.Driver");  
    conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/table","root","123456");//对应的是IP--用户名--密码
    PreparedStatement ps = conn.prepareStatement(sql);
    ResultSet rs = ps.executeQuery();//这里是执行sql语句,并把结果返回给rs这个对象,其中resultset是sql包自带的类,不要担心
    if(rs != null){//下面的代码是告诉你如何取出来刚才查到的数据
    flows = new ArrayList<OrderFlow>();
    while(rs.next()){
            OrderFlow flow = new OrderFlow();
            flow.setFlowinfo(rs.getString("flowinfo"));
            flow.setOrderid(rs.getString("orderid"));
            flow.setOrderinfo(rs.getString("orderinfo"));
            flow.setUname(rs.getString("uname"));
            flows.add(flow);

      }
    }

首先引入mysql-connector-java-5.1.37.jar这个jar包,然后下面代码就可以连接了:

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

Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "");

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("select * from user");
三楼 方式

JDBC啊,感觉这个问题很奇怪,应该是怎么使用java连接Mysql数据库吧,eclipse是的ide,不能连接mysql啊

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
eclipse C++ 如何连接mysql???
如题... 我把mysql目录里的include 加到IDE里了 但是要用到libmysql.lib 我不知道怎么把这个加进去... 一加进去就报错? 求高手帮解决 在线等
Eclipse与mysql的连接问题
我用的是mysql数据库,可是一直连不上,写了代码测试rnimport java.sql.*;rnpublic class eclipse rnrn public static void main(String[] args) rn // TODO Auto-generated method stubrn tryrn rn Class.forName("org.gjt.mm.mysql.Driver");rn Connection conn = DriverManager.getConnection("jdbc:mysql://localhost","root","86539024");rn System.out.println("连接成功");rn rn catch (ClassNotFoundException cnfex) rn System.out.println("装载JDBC/ODBC 驱动程序失败"); rn cnfex.printStackTrace(); rn rn catch (Exception ex) rn System.out.println("NoClassDefException"); rn ex.printStackTrace(); rn rn rn rnrnrn请各位高手帮我看下是怎么回事?rn在网上查说是数据库驱动没有连好,但开始我的错误是“装载JDBC/ODBC 驱动程序失败”rn我又把驱动复制放好,环境变量重新设置,再运行不是驱动失败变成rn出现错误如下rnjava.sql.SQLException: No suitable driverrn at java.sql.DriverManager.getConnection(DriverManager.java:545)rn at java.sql.DriverManager.getConnection(DriverManager.java:171)rn at eclipse.main(eclipse.java:9)rn
Eclipse连接MySql的问题
在Eclipse中连接MySql5.0,下载了mysql-connector-java-5.0.8-bin.jar,在系统环境变量中加入了classpath=jar所在的路径,在Eclipse下的DataSourceExplore->DataBase下添加数据库(还没有创建工程),连接数据库时出现如下错误:rnjava.lang.NoClassDefFoundError: org/aspectj/lang/Signaturern at java.lang.Class.getDeclaredConstructors0(Native Method)rn at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)rn at java.lang.Class.getConstructor0(Unknown Source)rn at java.lang.Class.newInstance0(Unknown Source)rn at java.lang.Class.newInstance(Unknown Source)rn at org.eclipse.datatools.connectivity.db.generic.JDBCConnection.createConnection(JDBCConnection.java:86)rn at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:104)rn at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:53)rn at org.eclipse.datatools.connectivity.db.generic.JDBCConnectionFactory.createConnection(JDBCConnectionFactory.java:52)rn at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:77)rn at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:354)rn at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:57)rn at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)rnrn请问该如何解决。
eclipse连接mysql问题
package mypackage;rnrnimport java.sql.*;rnrnpublic class DataConnection rnrn /**rn * @param argsrn */rn public static void main(String[] args) rn // TODO 自动生成方法存根rn String driver = "com.mysql.jdbc.Driver";rn String url = "jdbc:MySQL://localhost/mydatabase";rn String user = "root";rn String password = "123";rn tryrn rn Class.forName( driver );rn Connection con = DriverManager.getConnection(url,user, password);rn String insert = "insert friends(id,name) values(?,?)";rn PreparedStatement prestatement = con.prepareStatement( insert );rn String[] names = "rachel","rose","phoebe","monica","chandler","joey";rn rn for(int i = 0;i < 6;i++)rn rn prestatement.setInt(1, i);rn prestatement.setString(2, names[i]);rn prestatement.execute();rn rn String query = "select * from friends";rn ResultSet result = (ResultSet) prestatement.executeQuery( query );rn while(result.next())rn rn System.out.println(result.getString("name"));rn rn rn catch(SQLException e)rn rn e.getMessage();rn catch(ClassNotFoundException e)rn rn e.getMessage();rn rnrn rnrnrn院程序代码如上,从网上当了个MYSQL驱动mysql-connector-java-5.0.5-bin,工程的java build path的libraries中,但是程序执行到Class.forName( driver );抛出异常,Source not found(driver (non registeringdriver)).请求高手救助!
eclipse连接mysql的问题。
import java.sql.*;rnpublic class MysqlJdbc rn public static void main(String args[]) rn try rn Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序 rn //Class.forName("org.gjt.mm.mysql.Driver");rn System.out.println("Success loading Mysql Driver!");rn rn catch (Exception e) rn System.out.print("Error loading Mysql Driver!");rn e.printStackTrace();rn rn try rn Connection connection = DriverManager.getConnection(rn "jdbc:mysql://localhost:3306/test","root","8566");rn //连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码rnrn System.out.println("Success connect Mysql server!");rn Statement stmt = connection.createStatement();rn ResultSet rs = stmt.executeQuery("select * from user");rn //user 为你表的名称rn while (rs.next()) rn System.out.println(rs.getString("name"));rn rn rn catch (Exception e) rn System.out.print("get data error!");rn e.printStackTrace();rn rn rnrnrn运行后出现下面信息,不知道是怎么了?rnrn rn rn The user to connect asrn rn rn The password to use when connectingrn rn rn The name of the class that the driver should use for creating socket connections to the server. This class must implement the interface 'com.mysql.jdbc.SocketFactory' and have public no-args constructor.rn rn rn Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to '0'.rn rn rn Timeout on network socket operations (0, the default means no timeout).rn rn rn Load the comma-delimited list of configuration properties before parsing the URL or applying user-specified properties. These configurations are explained in the 'Configurations' of the documentation.rn rn rn Set the CLIENT_INTERACTIVE flag, which tells MySQL to timeout connections based on INTERACTIVE_TIMEOUT instead of WAIT_TIMEOUTrn rn rn Hostname or IP address given to explicitly configure the interface that the driver will bind the client side of the TCP/IP connection to when connecting.rn rn rn An implementation of com.mysql.jdbc.ConnectionPropertiesTransform that the driver will use to modify URL properties passed to the driver before attempting a connectionrn rn rn Use zlib compression when communicating with the server (true/false)? Defaults to 'false'.rn rn rn rn rn ……rn下面还有好多,贴不完了。。。
eclipse连接mysql报错
在连接数据库的测试过程中报错,不知道该怎么解决?rn错误: 找不到或无法加载主类 jdbc.sqltest
eclipse怎连接mysql
eclipse怎连接mysql啊rneclipse3.4.2;rnmysql5.1.46rnmysql-connector-java-5.1.6-bin;rnrnrnrnrnimport java.sql.*;rnpublic class conn rn public static void main(String args[]) rn try rn Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序 rn //Class.forName("org.gjt.mm.mysql.Driver");rn System.out.println("Success loading Mysql Driver!");rn rn catch (Exception e) rn System.out.print("Error loading Mysql Driver!");rn e.printStackTrace();rn try rn Connection connect = DriverManager.getConnection(rn "jdbc:mysql://localhost:3306/mysql","root","123456789");rn //连接URL为 jdbc:mysql//服务器地址/数据库名rn //后面的2个参数分别是登陆用户名和密码rn System.out.println("Success connect Mysql server!"); Statement stmt = connect.createStatement();rn ResultSet rs = stmt.executeQuery("select * from help_topic");rn while (rs.next()) rn System.out.println(rs.getString("name")); rn rn catch (Exception e) rn System.out.print("get data error!");rn e.printStackTrace();rn rn rn rnrnrnrn运行时错误:rnjava.lang.ClassNotFoundException: com.mysql.jdbc.Driverrn at java.net.URLClassLoader$1.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClassInternal(Unknown Source)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Unknown Source)rn at conn.main(conn.java:5)rnError loading Mysql Driver!java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mysqlrn at java.sql.DriverManager.getConnection(Unknown Source)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at conn.main(conn.java:13)rnget data error!
eclipse 连接mysql
%%%% Error Creating SessionFactory %%%%rnorg.hibernate.HibernateException: JDBC Driver class not found: com.mysql.jdbc.Driverrn at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)rn at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)rn at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)rn at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)rn at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)rn at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)rn at com.yourcompany.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:60)rn at com.yourcompany.HibernateSessionFactory.getSession(HibernateSessionFactory.java:43)rn at com.hibernate.BaseHibernateDAO.getSession(BaseHibernateDAO.java:14)rn at com.hibernate.AdminDAO.save(AdminDAO.java:27)rn at com.yourcompany.struts.action.AddAdminAction.execute(AddAdminAction.java:47)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)rn at java.lang.Thread.run(Thread.java:595)rnCaused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driverrn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1363)rn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1209)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:164)rn at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)rn at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)rn ... 31 more
eclipse连接mysql出错
![图片说明](https://img-ask.csdn.net/upload/201704/23/1492922645_61012.png)nn![图片说明](https://img-ask.csdn.net/upload/201704/23/1492922654_916799.png)nn这段代码图片放不上去 就复制下nnpackage com.buy.bean.comm.database;nimport java.sql.Connection;nimport java.sql.DriverManager;nimport java.sql.SQLException;nimport java.sql.Statement;nnpublic class DBConnect n n public static Connection getConnection() //获得数据库连接n Connection conn = null; //建立连接,初值为空n try n Class.forName(Config.CONNECTION_DRIVER).newInstance();n //获得配置文件的接口n conn = DriverManager.getConnection(Config.CONNECTION_URL, //取得连接n Config.CONNECTION_USER, Config.CONNECTION_PWD);n catch (Exception e) n e.printStackTrace(); //如果出错抛出异常n n if(conn == null) n System.out.println("no get connection! thrwos Exception");n //如果没有取得连接打印信息n n return conn; //返回连接n nnn```n n```nnnn![图片说明](https://img-ask.csdn.net/upload/201704/23/1492922419_806304.png)nn密码没有错 刚开始打项目 不太懂 希望帮忙下。
MySQL与eclipse建立连接
步骤: 1).MySQL中建立数据库——建立表——添加数据信息。 2).mysql与eclipse建立连接。 3).测试连接是否成功。 1) ctrl+R —— 输入:cmd —— 回车 输入命令:mysql -u root -p        【进入MySQL数据库】 输入密码:******             【输入密码】 输入命令:create databas
eclipse 和 mysql 连接
驱动mysql-connector-java-5.0.3.zip解压后把mysql-connector-java-5.0.3-bin.jar放入c:j2sdk和d:tomcat/common下,并在环境变量中加了路径rn用ECLIPSE运行以下代码:rnrnimport java.sql.*;rnrnrnpublic class personrnrnrnrn private static final String Drivermanager = null;rnrn public static void main(String args[])rn Connection conn= null;rn tryrnrn rn Class.forName("com.jdbc.mysql.Driver").newInstance();rn rn rn System.out.print("连接成功");rn catch(Exception e)rnrn rnrn System.out.println(e);rn System.out.print("连接失败");rn rn rnrnrn调试结果:java.lang.ClassNotFoundException: com.jdbc.mysql.Driver连接失败 rn请高手门讲讲,不胜感激!!!rn
eclipse连接MySQL失败
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driverrn at java.net.URLClassLoader$1.run(Unknown Source)rn at java.net.URLClassLoader$1.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Unknown Source)rn at itcast.Demo.JDBCDemo.main(JDBCDemo.java:26)rnEclipse中显示以上问题无法解决,求救!
eclipse连接mysql的问题
为什么我的查询结果是如下:rnrn驱动程序连接成功rn数据库连接成功!rn1 ??±? ?? °?????·??? rn
Eclipse连接Mysql的jar包
Eclipse连接Mysql的jar包,解决连接不上的问题,除了将jar包添加到项目中进行build path之外,还需要把jar包放到java安装目录的lib文件夹中的ext中,连接成功
Eclipse jsp连接mysql?
同样的代码,添加了mysql-connector-java-5.1.15-bin.jar到Build Path。rn[code=Java]<%@ page import="com.mysql.jdbc.Driver" %>rnrn<%@ page import="java.sql.*" %>rnrn<%rn//驱动程序名rnrnString driverName="com.mysql.jdbc.Driver";rnrn//数据库用户名rnrnString userName="kong";rnrn//密码rnrnString userPasswd="kong";rnrn//数据库名rnrnString dbName="clientsmanager";rnrn//表名rnrnString tableName="customer";rnrn//联结字符串rnrnString url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;rnrnClass.forName("com.mysql.jdbc.Driver").newInstance();rnrnConnection connection=DriverManager.getConnection(url);rnrnStatement statement = connection.createStatement();rnrnString sql="SELECT * FROM "+tableName;[/code]rn在netbean里面可以连接,在eclipse里面出错。显示找不到Class.forName("com.mysql.jdbc.Driver");rn如果注释掉改行就出现:rnNo suitable driver found for jdbc:mysql://localhost/clientsmanager?user=kong&password=kongrn这是怎么回事?
Eclipse 连接mysql问题
[img=http://img.my.csdn.net/uploads/201301/01/1357014900_9862.jpg][/img] 请问这个问题如何解决, 在myeclipse里面没有问题,但是在eclipse里和lomboz eclipse里就出现这个问题,
Eclipse 连接mysql 的问题
import java.sql.*; rnrnpublic class connectmysql rnpublic static void main(String agrs[]) rnString driver ="com.mysql.jdbc.Driver"; rnString url="jdbc:mysql://localhost:3306/test"; rnString user="root"; rnString password="123"; rntry rnClass.forName(driver); rn rncatch(Exception e) rnSystem.out.println("无法加载驱动程序"+driver); rn rntry rnConnection con=DriverManager.getConnection(url,user,password); rnif(!con.isClosed()) rnSystem.out.println("数据库连接成功"); rncon.close(); rn rncatch(SQLException ee) rnSystem.out.println("数据库连接失败"); rn rn rnrnrn运行结果 :rn无法加载驱动程序com.mysql.jdbc.Driverrn数据库连接失败rnrn有人说没有驱动,我下了个。可是不知道怎么添加进去。驱动版本 mysql-connector-java-3.1.11-bin.jar 可是我总是看不懂网上说的怎么回事。有人说加到 WRB-INF下的lib 可是我几乎在我电脑里面所有的都添加了还是没有用。 又有说用eclipse加载,可是我不知道怎么添加。看论坛里面的回答按照做后总是发现要么不对,要么就是不一样不会再按照做了!
Eclipse下连接MySql的问题
初学Java数据库编程,下面的程序目的大概是测试一下能否连接到本机上的MySQL数据库,在把驱动路径加到CLASSPATH里后,在控制台里直接编译并java MakingTheConnection 能够运行成功;但是当我在Eclipse里新建一个项目,并加入该类时,却抛出异常: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driverrnrn请问如果要在Eclipse里允许该程序,还需做什么操作?rnrn//The code:rnimport java.sql.*;rnrnpublic class MakingTheConnection rnrn public static void main(String[] args) rn rn tryrn Class.forName("org.gjt.mm.mysql.Driver");//Load the driver classrn rn //Define the data source for the driverrn String sourceURL= "jdbc:mysql://127.0.0.1:3306/teacher?user=root&password=";rn //Create a connection through the DriverManagerrn Connection databaseConnection=DriverManager.getConnection(sourceURL);rn rn System.out.println("Connection established successfully!");rn rn databaseConnection.close();//close connectionrn catch(ClassNotFoundException cnfe)rn System.err.println(cnfe);rn rn catch(SQLException sqle)rn System.err.println(sqle);rn rn rn
Eclipse C 连接 mysql
通过Eclipse CDT环境用MinGW(gcc)编译连接mysql的静态库。
Mysql的基本操作与连接eclipse
mysql的命令行界面使用安装部分 请自行百度下载这个:mysql-installer-community-5.7.17.0.msi,一路next至安装完成登陆部分 找到安装目录,我的目录如下: C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql.exe” 目录的空白地方按下Ctrl+鼠标右键,点击“在此处打开目录窗口”,打开命令行界面 输入
eclipse 与 mysql连接问题
驱动mysql-connector-java-5.0.3.zip解压后把mysql-connector-java-5.0.3-bin.jar放入c:j2sdk和d:tomcat/common下,并在环境变量中加了路径rn用ECLIPSE运行以下代码:rnrnimport java.sql.*;rnrnrnpublic class personrnrnrnrn private static final String Drivermanager = null;rnrn public static void main(String args[])rn Connection conn= null;rn tryrnrn rn Class.forName("com.jdbc.mysql.Driver").newInstance();rn rn rn System.out.print("连接成功");rn catch(Exception e)rnrn rnrn System.out.println(e);rn System.out.print("连接失败");rn rn rnrnrn调试结果:java.lang.ClassNotFoundException: com.jdbc.mysql.Driver连接失败 rn我不清楚是什么原因导致连接失败,请高手门讲讲,不胜感激!!!rn
eclipse连接mysql驱动错误
问题与错误平时在公司里也有使用hibernate3,今天在家里自己建了一个来测试,结果出现了一个错误。找了很久也没找到,刚开始以为是驱动不对,最后发现其实是URL写错了。No suitable driver found for jdbc:mysql//localhost:3306/test工具与环境 eclipse juno window 8 mysql5.6.21 mysql-connector-
Eclipse与Mysql驱动连接的问题
//public static final String DBDRIVER="org.git.mm.mysql.Driver"; 用这个时死活连不通; 但是用这个老版本的时候就可以。 public static final String DBDRIVER="com.mysql.jdbc.Driver"; 感谢师姐
Eclipse连接Mysql超详细教程
        今天介绍的是eclipse如何与MySQL相连,相信很多小伙伴和我一样,对路径啊,什么包放在那里啊很是头疼,今天一下午才弄好就赶来分享啦,超详细哦! 准备工作:下载MySQL和jdbc,这里就不讲了,注意的是你可能已经下载了MySQL,但是没有下载jdbc,它们的下载是分开的,所以你可以先看看本文后面的一些步骤,先确定自己有没有下载jdbc,没下载的去官网下载一下,只有几兆,非常...
eclipse与mysql建立连接问题
eclipse与mysql建立连接的时候出现了这样的问题: Exception in thread “main” java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES) 解决办法:一,查看连接服务器的密码和连接是否出错 二,导入的驱动包的版本是否可行,在我的电脑上视频里面用的版本是...
eclipse连接mysql遇到的问题
同样的servlet,直接运行tomcat访问数据库,完全正常,但是通过eclipse启动tomcat访问mysql则会出现下面的提示。rncom.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: rnrn** BEGIN NESTED EXCEPTION ** rnrnjava.net.SocketExceptionrnMESSAGE: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)rnrnSTACKTRACE:rnrnjava.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)rn at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)rn at com.mysql.jdbc.MysqlIO.(MysqlIO.java:276)rn at com.mysql.jdbc.Connection.createNewIO(Connection.java:2666)rn at com.mysql.jdbc.Connection.(Connection.java:1531)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at ch8.GetDBInfoServlet.doGet(GetDBInfoServlet.java:34)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)rn at java.security.AccessController.doPrivileged(Native Method)rn at javax.security.auth.Subject.doAsPrivileged(Unknown Source)rn at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)rn at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:245)rn at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:50)rn at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:156)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:152)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)rn at java.lang.Thread.run(Unknown Source)rnrnrn** END NESTED EXCEPTION **rnrnrnrnLast packet sent to the server was 0 ms ago.rn at com.mysql.jdbc.Connection.createNewIO(Connection.java:2741)rn at com.mysql.jdbc.Connection.(Connection.java:1531)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at ch8.GetDBInfoServlet.doGet(GetDBInfoServlet.java:34)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)rn at java.security.AccessController.doPrivileged(Native Method)rn at javax.security.auth.Subject.doAsPrivileged(Unknown Source)rn at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)rn at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:245)rn at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:50)rn at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:156)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:152)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)rn at java.lang.Thread.run(Unknown Source)rnrn原代码中出错的地方rn public boolean init()rn tryrn Class.forName(driverClass);rn catch(ClassNotFoundException ce)rn ce.printStackTrace();rn return false;rn rn //if(conn==null)rn tryrn conn=DriverManager.getConnection(url, user, password);rn stmt=conn.createStatement();rn catch(SQLException se)rn se.printStackTrace();rn return false;rn rn //rn return true;rn rn
eclipse 连接mysql问题 求助
import java.sql.*;rnpublic class Mysqljdbc rn public static void main(String args[]) rn try rn Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序 rn //Class.forName("org.gjt.mm.mysql.Driver");rn System.out.println("Success loading Mysql Driver!");rn rn catch (Exception e) rn System.out.print("Error loading Mysql Driver!");rn e.printStackTrace();rn rn try rn Connection connect = DriverManager.getConnection(rn "jdbc:mysql://localhost:3306/test","root","");rn //连接URL为 jdbc:mysql//服务器地址/数据库名 ,后面的2个参数分别是登陆用户名和密码rnrn System.out.println("Success connect Mysql server!");rn Statement stmt = connect.createStatement();rn ResultSet rs = stmt.executeQuery("select * from user");rn //user 为你表的名称rnwhile (rs.next()) rn System.out.println(rs.getString("name"));rn rn rn catch (Exception e) rn System.out.print("get data error!");rn e.printStackTrace();rn rn rnrnrn上面是代码 下面是eclipse控制台输出rnrnrnrn rn rn The user to connect asrn rn rn The password to use when connectingrn rn rn The name of the class that the driver should use for creating socket connections to the server. This class must implement the interface 'com.mysql.jdbc.SocketFactory' and have public no-args constructor.rn rn rn Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to '0'.rn rn rn Timeout on network socket operations (0, the default means no timeout).rn rn rn Load the comma-delimited list of configuration properties before parsing the URL or applying user-specified properties. These configurations are explained in the 'Configurations' of the documentation.rn rn rn Set the CLIENT_INTERACTIVE flag, which tells MySQL to timeout connections based on INTERACTIVE_TIMEOUT instead of WAIT_TIMEOUTrn rn rn Hostname or IP address given to explicitly configure the interface that the driver will bind the client side of the TCP/IP connection to when connecting.rn rn rn An implementation of com.mysql.jdbc.ConnectionPropertiesTransform that the driver will use to modify URL properties passed to the driver before attempting a connectionrn rn rn Use zlib compression when communicating with the server (true/false)? Defaults to 'false'.rn rn rn rn rn If connecting using TCP/IP, should the driver set SO_KEEPALIVE?rn rn rn If connecting using TCP/IP, should the driver set SO_TCP_NODELAY (disabling the Nagle Algorithm)?rn rn rn If connecting using TCP/IP, should the driver set SO_RCV_BUF to the given value? The default value of '0', means use the platform default value for this property)rn rn rn If connrnrn
eclipse 连接 MySQL 数据库的基本操作
eclipse 连接 MySQL 数据库的基本操作 java 是面向对象的语言 DB是sql语言,即结构化查询语言 1. jar文件 java代码要想操作数据库需要引入jar文件 jar文件是eclipse连接数据库的驱动文件. jar文件可在网上自行搜索下载. 2 eclipse中导入jar包 eclipse中新建项目,直接把...
eclipse rcp 客户端MySQL连接
eclipse rcp 客户端MySQL连接
eclipse环境连接MySQL问题
 如果你找到这里,说明你找了很久了下面阅读需要2分钟... Access denied for user 'root'@'localhost' (using password: YES) 以上问题,我已经找了很多解决办法,都无法解决。 问题:Navicat和命令行可以连接MySQL,eclipse不能连接,问题待解决,...
eclipse连接mysql一直报错
[img=https://img-bbs.csdn.net/upload/201701/10/1484043227_773967.png][/img][img=https://img-bbs.csdn.net/upload/201701/10/1484043238_362793.png][/img]
Mysql的基本操作与连接sts\eclipse
MSQL的基本操作与使用   1.MySQL解压版的安装   解压mysql-8.0.11-winx64.zip 设置数据存放的目录: basedir=C:\Mysql\mysql-8.0.11-winx64 datadir=C:\Mysql\mysql-8.0.11-winx64\data 用管理员账号打开cmd,然后,找到C:\Program Files\Mysql\mysql-...
Eclipse中连接MySQL的问题!
用Eclipse连接MySQL的问题。我安装了Eclipse3.2和MySQL 5.0和mysql-connector-java-5.0.4.zip。写了一个程序但是不好用:rnpackage mypackage;rnrnimport java.sql.*;rnrnpublic class DataConnection rnrn public static void main(String [] args) rn rn String driver = "com.mysql.jdbc.Driver";rn String url = "jdbc:mysql://localhost/mydatabase";rn String user = "root";rn String password = "123123";rn rn rn tryrn rn Class.forName(driver);rn Connection con = DriverManager.getConnection(url,user,password); rn String insert = "insert friends(id,name) values(?,?)";rn PreparedStatement prestatement = con.prepareStatement(insert);rn String [] names = "Rachel","Rose","Phoebe","Monica","Chandler","Joey";rn for(int i = 0;i < 6;i++ )rn rn prestatement.setInt(1,i);rn prestatement.setString(2,names[i]);rn prestatement.execute();rn rn rn String query = "select * from friends";rn ResultSet result = prestatement.executeQuery(query);rn rn System.out.println("The Results is:");rn while (result.next())rn rn System.out.println(result.getString("name"));rn rn con.close();rn rn catch(SQLException e)rn rn e.printStackTrace();rn catch (ClassNotFoundException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn rnrn在下面显示以下问题,请教大家是什么问题?rnjava.lang.ClassNotFoundException: com.mysql.jdbc.Driverrn at java.net.URLClassLoader$1.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClassInternal(Unknown Source)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Unknown Source)rn at mypackage.DataConnection.main(DataConnection.java:17)rn
Eclipse Java连接Mysql出错
用正常连接数据库代码运行后出现,好像是MySQL访问地址问题,怎么解决?nerror:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communication link failure, message from server: "Can't get hostname for your address"
Windows平台eclipse连接Mysql解决方案
1、  eclipse的db.properties配置 db.driverClassName=com.mysql.jdbc.Driver db.url=jdbc:mysql://localhost:3306/“数据库名”?characterEncoding=utf8 db.username=用户登录名 db.password=用户密码2
关于eclipse的mysql连接配置
打开eclipse,选择Window→Open Perspective→Other→Database Development,然后在右边的导航栏右键点击Database Connections文件夹,选择new,选择MySQL,选next,进行相关的配置。 如果没有驱动,先定义一个新的驱动,点击Drivers栏后边的图标进行New Driver Definition: 1.在Name/Type
eclipse连接MySQL出现的错误
我是一个初学者,当用eclipse连接MySQL时,在eclipse中写入数据,出现java.sql.SQLException: Column count doesn't match value count at row 1;一开始百度都说写的格式与MySQL的列不一样,最后发现时创建的表的格式与写入的数据格式不相同,例如我开始的表的格式是varchar(20),varchar(20),但是我写入...
使用Eclipse下的JAVA连接MySQL
OS:win7 IDE:Eclipse Mars DB:MySQL 5.6 Connector:Connector.J 5.1 参考了这个帖子,但是有1个改动。 http://database.51cto.com/art/201006/204217.htm 改动有:(1)无需在classpath里面加入什么jar包路径,直接向工程导入jar包即可。 Project
终于解决了mysql与eclipse的连接
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)关于jdbc连接数据库的这个问题,我自己已经找了两天.始终写的是密码错误,请使用正确的密码.我反复尝试之后觉得密码没有错,甚至又重新看了orcl的视频,又重新安装了plsql,找到了破解plsql的工具,并且重新使用Scott用...
eclipse连接Oracle.sqlserver,mysql的设置
eclipse连接Oracle.sqlserver,mysql的设置
相关热词 c++和c#哪个就业率高 c# 批量动态创建控件 c# 模块和程序集的区别 c# gmap 截图 c# 验证码图片生成类 c# 再次尝试 连接失败 c#开发编写规范 c# 压缩图片好麻烦 c#计算数组中的平均值 c#获取路由参数