Android 通过jdbc 直连MySql 连不上

本人新手,找了好多资源,测试直连的问题,这些代码也是本网站找的,自己稍微改了一下,为何死活连不上去,conn返回都是空的,大神帮我看看。
public class MainActivity extends Activity {

private static final String URL = "jdbc:mysql://www.luhef.cn:3306/xh";
private static final String USER = "*******";
private static final String PASSWORD = "*****";

private Connection conn;
private Button onConn;
private Button onInsert;
private Button onDelete;
private Button onUpdate;
private Button onQuery;
private Handler handler = new Handler() {

    public void handleMessage(Message msg) {
        String str = (String) msg.obj;
        Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
    };
};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    onConn = (Button) findViewById(R.id.onConn);
    onInsert = (Button) findViewById(R.id.onInsert);

}

@Override
protected void onDestroy() {
    super.onDestroy();
    if (conn != null) {
        try {
            conn.close();
        } catch (SQLException e) {
            conn = null;
        } finally {
            conn = null;
        }
    }
}

public void onConn(View view) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            conn = Util.openConnection(URL, USER, PASSWORD);
            Message msg = new Message();
            msg.obj = conn;
            handler.sendMessage(msg);
        }
    }).start();
}

public void onInsert(View view) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            String sql = "insert into users values(15, 'xiaoming')";
            Util.execSQL(conn, sql);
            Log.i("onInsert", "onInsert");
        }
    }).start();
}

}

package com.lyz.learning.mysqlandandroid;

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

public class Util {
final static String DRIVER_NAME = "com.mysql.jdbc.Driver";

public static Connection openConnection(String url, String user,
                                        String password) {
    Connection conn = null;
    try {
        Class.forName(DRIVER_NAME);
        conn = DriverManager.getConnection(url, user, password);
    } catch (ClassNotFoundException e) {
        conn = null;
    } catch (SQLException e) {
        conn = null;
    }
    System.out.println(conn);

    return conn;
}

public static void query(Connection conn, String sql) {
    if (conn == null) {
        return;
    }
    Statement statement = null;
    ResultSet result = null;
    try {
        statement = conn.createStatement();
        result = statement.executeQuery(sql);
        System.out.println(result);
        if (result != null && result.first()) {
            int idColumnIndex = result.findColumn("id");
            int nameColumnIndex = result.findColumn("name");
            System.out.println("id\t\t" + "name");
            while (!result.isAfterLast()) {
                System.out.print(result.getString(idColumnIndex) + "\t\t");
                System.out.println(result.getString(nameColumnIndex));
                result.next();
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (result != null) {
                result.close();
                result = null;
            }
            if (statement != null) {
                statement.close();
                statement = null;
            }} catch (SQLException sqle) {
            sqle.printStackTrace();
        }
    }
}

public static boolean execSQL(Connection conn, String sql) {
    boolean execResult = false;
    if (conn == null) {
        return execResult;
    }
    Statement statement = null;
    try {
        statement = conn.createStatement();
        if (statement != null) {
            execResult = statement.execute(sql);
        }
    } catch (SQLException e) {
        execResult = false;
    }
    return execResult;
}

}

10个回答

是否在Manifest中配置了相关的网络权限和读写权限?

cry8801
cry8801 都配置过的,还是不行
一年多之前 回复
cry8801
cry8801 点错了,点了采纳。
一年多之前 回复
 query_cache_type:控制 Query Cache 功能的开关,可以设置为0(OFF),1(ON)和2(DEMAND)三种,意义分别如下:

0(OFF):关闭 Query Cache 功能,任何情况下都不会使用 Query Cache

1(ON):开启 Query Cache 功能,但是当 SELECT 语句中使用的 SQL_NO_CACHE 提示后,将不使用Query Cache

2(DEMAND):开启 Query Cache 功能,但是只有当 SELECT 语句中使用了 SQL_CACHE 提示后,才使用 Query Cache

数据库的问题。从这方面入手

cry8801
cry8801 谢谢,明天我再弄一下看看
一年多之前 回复

1.你是使用的,mysql数据库的链接方式吗
2.mysql数据库的链接方式是这样的:
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicod
e=true&characterEncoding=8859_1"
//myDB为数据库名
Connection conn= DriverManager.getConnection(url);

mengtianqq
ConfidentWU 或者你com.mysql.jdbc.Driver这个类还没有引入的,你引入试试
一年多之前 回复
mengtianqq
ConfidentWU 估计你要把Class.forName(DRIVER_NAME)写成:Class.forName(DRIVER_NAME).newInstance()
一年多之前 回复
mengtianqq
ConfidentWU 估计你要把Class.forName(DRIVER_NAME)写成:
一年多之前 回复

www.luhef.cn:3306

这个域名的数据库肯定没有开放让你直接访问。

cry8801
cry8801 可以访问的,我用vb也可以远程连接操作的
一年多之前 回复

你的数据库user 和 Password改没有?

cry8801
cry8801 回复txgrzy: 可以帮忙做一段试试么我把帐号和密码给你
一年多之前 回复
cry8801
cry8801 回复txgrzy: 有的,导入了的。
一年多之前 回复
txgrzy
txgrzy 回复cry8801: 看你代码中隐去了,所以问下,访问数据库需要导入一个jar包,不知道你有没有,一起我做的时候总是忘了。
一年多之前 回复
cry8801
cry8801 改的,数据库方面没问题
一年多之前 回复

异常提示呢?发来看看

cry8801
cry8801 异常信息传上来了,帮忙看看。
一年多之前 回复

异常信息来了,帮忙分析分析。图片

图片说明

cry8801
cry8801 引入了的,刚刚在my.cnf里加了query_cache_type=0,导致数据库都登录不了了。
一年多之前 回复

结案,已解决问题,参照大神意见,换了jdbc驱动,mysql 版本5.1.73,jdbc驱动5.1.6.

我想问一下,怎么 mysql 8.0 下 用 mysql-connector-java-8.0.16.jar 死活上不了.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
通过JDBC直连mysql数据库
首先要导入mysql jar包 mysql-connector-java-5.1.30.jar 代码: package testJDBC; import java.sql.*; public class MainTest { private static String driver = "com.mysql.jdbc.Driver"; private static St...
Android如何通过JDBC直连访问MySQL数据库?
请各位大佬帮忙看看这段代码哪里出了问题,无法连接数据库,权限和架包都已经弄好了,但是就是不行rnpackage com.example.mysql_1;rnrnimport android.os.Bundle;rnimport android.os.Handler;rnimport android.os.Message;rnimport android.support.v7.app.AppCompatActivity;rnimport android.util.Log;rnrnimport java.sql.Connection;rnimport java.sql.DriverManager;rnimport java.sql.ResultSet;rnimport java.sql.SQLException;rnimport java.sql.Statement;rnrnpublic class MainActivity extends AppCompatActivity rnrn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rn Log.i("123123", "000功");rn new Thread(runnable).start();rn rn Handler myHandler = new Handler()rn public void handleMessage(Message msg)rn super.handleMessage(msg);rn Bundle data = new Bundle();rn data=msg.getData();rn System.out.println("username" + data.get("username").toString());rn System.out.println("userpass" + data.get("userpass").toString());rn rn ;rn Runnable runnable = new Runnable() rn private Connection connection = null;rnrn @Overridern public void run() rn try rn Class.forName("com.mysql.jdbc.Driver");rn connection = DriverManager.getConnection("jdbc:mysql://192.168.191.88/aaa", "root", "123456");rn Log.i("123123", "连接成功");rn catch (ClassNotFoundException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn catch (SQLException e1) rn e1.printStackTrace();rn rn try rn test(connection); //测试数据库连接rn catch (java.sql.SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rnrn public void test(Connection con1) throws java.sql.SQLException rn try rn String sql = "select * from user"; //查询表名为“user”的所有内容rn Statement stmt = con1.createStatement(); //创建Statementrn ResultSet rs = stmt.executeQuery(sql); //ResultSet类似Cursorrnrn //ResultSet最初指向第一行rn Bundle bundle = new Bundle();rn while (rs.next()) rn bundle.clear();rn bundle.putString("username", rs.getString("username"));rn bundle.putString("userpass", rs.getString("userpass"));rn Message msg = new Message();rn msg.setData(bundle);rn myHandler.sendMessage(msg);rn rnrn rs.close();rn stmt.close();rn catch (SQLException e) rnrn finally rn if (con1 != null)rn try rn con1.close();rn catch (SQLException e) rn rn rn rn ;rnrn希望大佬们能够解答!!!
jdbc 直连sql server 2000 连不上
com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。rn[code=SQL] at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)rn at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049)rn at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)rn at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)rn at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)rn at java.sql.DriverManager.getConnection(DriverManager.java:582)rn at java.sql.DriverManager.getConnection(DriverManager.java:185)rn at database.JDBC_Connection.getcConnection(JDBC_Connection.java:28)rn at database.JDBC_Connection.main(JDBC_Connection.java:41)[/code]rnrn[img=http://pic002.cnblogs.com/images/2012/370953/2012050415122513.png][/img]
jdbc直连
内涵msbase.jar、mssqlserver.jar、msutil.jar三个Java直连的jar包
100分!!!!!!!!!!!!!JDBC连不上MySQL
java.sql.SQLException: No suitable driver found for rootrn at java.sql.DriverManager.getConnection(DriverManager.java:689)rn at java.sql.DriverManager.getConnection(DriverManager.java:247)rn at com.xxsk.dao.Database.connect(Database.java:16)rn at com.xxsk.dao.Database.getConnection(Database.java:30)rn at com.xxsk.dao.DownloadDao.getFileList(DownloadDao.java:19)rn at com.xxsk.service.DownloadService.getFileList(DownloadService.java:15)rn at com.xxsk.servlet.DownloadServlet.service(DownloadServlet.java:28)rnrnMySQL JAR包:mysql-connector-java-5.1.38-bin.jar,已经放到项目的lib目录里面了rnMySQL数据库用的是5.7的版本。rnrn不知道是不是版本的问题,官网上没有5.1的数据库也没有5.7的JAR包下载,郁闷。
mysql一直连不上jdbc驱动?
在包的buildpath里选择Configure Buile Path,在“Libraries”一栏选择add External JARs,选中“mysql-connector-java-5.0.4-bin.jar”,OK以后就可以了是吗?还需不需要到我的电脑里配置环境变量?为何一直连接不上?下面是代码rnrnrn[code=Java]rnpackage database;rnrnimport java.sql.Connection;rnimport java.sql.DriverManager;rnimport java.sql.SQLException;rnrn/**rn *@author 作者:Xphrn *@version 创建时间:2010-3-9下午07:38:58rn */rnpublic class Mysql1 rn public String Url="jdbc:mysql://192.168.1.101:3306/mysql?user=root&password=123456";rn Connection conn=null;rn rn public Mysql1() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundExceptionrn rn tryrn rn Class.forName("com.mysql.jdbc.driver").newInstance();rn conn=DriverManager.getConnection(Url);rn System.out.println("Success loading Mysql Driver!");rnrn catch(Exception e)rn rn System.out.println("fail!");rn e.printStackTrace();rn rn rn public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundExceptionrn rn new Mysql1();rn rnrnrnrnrnrn报的错为:rnfail!rnjava.lang.ClassNotFoundException: com.mysql.jdbc.driverrn at java.net.URLClassLoader$1.run(URLClassLoader.java:200)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:188)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:307)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:252)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:169)rn at database.Mysql1.(Mysql1.java:19)rn at database.Mysql1.main(Mysql1.java:31)rnrn[/code]
新手,直连sql2000连不上,求教
Dim Conn As Data.SqlClient.SqlConnectionrn Dim cmd As System.Data.SqlClient.SqlCommandrn Dim rdr As System.Data.SqlClient.SqlDataReaderrn Dim ConnString As Stringrnrn ' 创建、打开数据库连接rn ConnString = "Data Source=(local);Initial Catalog=myPawn;Persist Security Info=True;User ID=sa"rn Conn = New Data.SqlClient.SqlConnection(ConnString)rn Conn.Open()------>SQL不存在或拒绝访问rnrn到底怎么才能连上pc的sql 2000啊?
mysql直连
mysql 直连方法
【Android】不要尝试用Android直连MySQL
在UI线程调用包含建立连接mysql语句的函数,得到的connection是null 直接将url,username,password 放在代码中,会被反编译看到的 傻逼才搞直连
通过Jdbc连接数据库(MySQL)
什么是JDBC: JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成。JDBC提供了一种基准,据此可以构建更高级的工具和接口,使数据库开发人员能够编写数据库应用程序. 一.在数据库中建立数据的表格 可以在dos命令框中执行,也可以用mysq
jdbc直连驱动
jdbc中用于SQLServer2000的驱动包,共三个文件
JDBC 直连的问题
public class sqlline rn public sqlline() rn rn rn public void read ()rn try rn Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");rn catch (Exception ex) rn System.out.println("加载驱动错误");rn rn rn Connection conn=null;rn Statement stmt=null;rn ResultSet rs=null;rn rn try rn conn=DriverManager.getConnection("jdbc:Microsoft:Sqlserver://localhost:databasename=stu:user=mwn:password=mwn");rn stmt=conn.createStatement();rn rs=stmt.executeQuery("select * from stu");rn rn while(rs.next())rn System.out.println(rs.getObject(1));rn System.out.println(rs.getObject(2));rn System.out.println(rs.getObject(3));rn System.out.println(rs.getObject(4));rn rn rn catch (Exception ex) rn System.out.println(ex.getMessage());rn finally rn try rn rs.close();rn stmt.close();rn conn.close();rn catch (Exception ex) rn System.out.println(ex.getMessage());rn rn rn rn rn rnrnrnrnrnrn提示错误:rnrn[Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.rnrnnullrnrn很不明白Connection的地方怎么会错的rnjdbc:Microsoft:Sqlserver://localhost:databasename=stu:user=mwn:password=mwn 的地方应该怎么写呢。rnrn还有一个问题,如果我把manager消息对话框给托没了,应该在哪把它调出来呢rnrn
怎样直连jdbc?hibernate+spring
提示rnjava.lang.UnsupportedOperationException: The user must supply a JDBC connectionrn org.hibernate.connection.UserSuppliedConnectionProvider.closeConnection(UserSuppliedConnectionProvider.java:37)rn com.action.TestAction.execute(TestAction.java:55)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn java.lang.reflect.Method.invoke(Unknown Source)rnrnrnrnpublic String execute() throws Exception rnConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider();rnConnection conn = null;rnStatement st = null;rnResultSet rs = null;rnString sql="select * from xt";rntry rnconn = cp.getConnection();rnst = conn.createStatement();rnrs = st.executeQuery(sql);rnif(rs.next())rnSystem.out.println((String)rs.getString("name"));rnrn catch (SQLException e) rne.printStackTrace();rnrnfinallyrntry rncp.closeConnection(conn);rn catch (SQLException e) rne.printStackTrace();rnrnrnreturn SUCCESS;rn
jdbc直连数据库的缺点
1.频繁的连接和释放,浪费资源,影响系统性能,如果使用数据库连接池可解决此问题。 2.硬编码问题,不便于后期的维护,实际应用中sql变化较大,从而java代码需要改动 3.使用preparedStatement向占有位符传递参数存在硬编码,因为sql语句where条件不一定,可能多也可能少,修改sql还要修改代码,不便于维护 4.对结果集解析存在硬编码,sql变化导致解析代码变化,系统不易维...
jdbc直连sqlserver问题~~!!
我的系统是winxp +sql2000 用的是eclipse sqlserver的驱动也在环境变量也设置好了 另外在eclipse里也把驱动加载了 程序在别的电脑上也可以运行 但一到我电脑上就出现rnjava.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.rn at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)rn at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn at com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)rn at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)rn at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at Mssql.MSsql.getConn(MSsql.java:19)rn at Mssql.MSsql.main(MSsql.java:37)rn 请教那为高人告诉我那里错了 谢谢了~!!
直连驱动JDBC
直连驱动JDBC
通过jdbc连不上mysql数据库 求大侠指导
[img=https://img-bbs.csdn.net/upload/201410/09/1412851736_727662.png][/img]rnrnrn2014-10-9 18:34:56 org.apache.catalina.core.StandardContext listenerStartrn严重: Exception sending context initialized event to listener instance of class com.lgm.common.web.WebContextrnorg.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: rn### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)rn### The error may exist in com/lgm/common/mappers/DictMapper.xmlrn### The error may involve com.lgm.common.mappers.DictMapper.queryAllDictrn### The error occurred while executing a queryrn### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)rn at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)rn at $Proxy54.selectList(Unknown Source)rn at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)rn at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114)rn at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)rn at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)rn at $Proxy55.queryAllDict(Unknown Source)rn at com.lgm.common.service.DictService.queryAllDict(DictService.java:27)rn at com.lgm.common.web.DictUtil.initDict(DictUtil.java:55)rn at com.lgm.common.web.WebContext.contextInitialized(WebContext.java:66)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1229)rn at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)rn at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)rn at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)rn at java.util.concurrent.FutureTask.run(FutureTask.java:138)rn at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)rn at java.lang.Thread.run(Thread.java:619)rnCaused by: org.apache.ibatis.exceptions.PersistenceException: rn### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)rn### The error may exist in com/lgm/common/mappers/DictMapper.xmlrn### The error may involve com.lgm.common.mappers.DictMapper.queryAllDictrn### The error occurred while executing a queryrn### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)rn at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)rn ... 23 morernCaused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)rn at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)rn at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)rn at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)rn at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:271)rn at org.apache.ibatis.executor.BatchExecutor.doQuery(BatchExecutor.java:80)rn at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)rn at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)rn at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:115)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)rn ... 29 morernCaused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)rn at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)rn at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)rn at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)rn at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)rn at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)rn ... 37 morernCaused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)rn at com.mysql.jdbc.Util.getInstance(Util.java:381)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)rn at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)rn at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2253)rn at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:718)rn at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:513)rn at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)rn at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)rn at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)rn at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)rn at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)rn at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)rn ... 41 morernCaused by: java.net.ConnectException: Connection timed out: connectrn at java.net.PlainSocketImpl.socketConnect(Native Method)rn at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)rn at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)rn at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)rn at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)rn at java.net.Socket.connect(Socket.java:519)rn at java.net.Socket.connect(Socket.java:469)rn at java.net.Socket.(Socket.java:366)rn at java.net.Socket.(Socket.java:209)rn at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)rn at com.mysql.jdbc.MysqlIO.(MysqlIO.java:280)rn at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2177)rn ... 54 morern2014-10-9 18:34:56 org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfigrn信息: Reading standard config META-INF/standard-faces-config.xmlrn2014-10-9 18:34:56 org.apache.myfaces.config.DefaultFacesConfigurationProvider getWebAppFacesConfigrn信息: Reading config /WEB-INF/faces-config.xmlrnrnrnrnrnrn网络没有任何问题,mysql的服务也启动了,配置文件也检查过 没问题 但是完全连不上mysql 求大神指导
在Android Studio中,用jdbc连接MySQL连不上
网上的很多方法都试过,还是不行,各位大神帮我看下什么原因。rn目前排除的原因:rn1.在单元测试中可以连接成功,并获得数据。所以数据库、连接格式应该没问题。rn2.connect-java包试了好几个版本都不行。rn3.在Activity中连接不上,但我已经放在新的线程中了,而且用好几种开启新线程的方式试过。rnrn以下是代码rn```rn public class MainActivity extends AppCompatActivity rn private Connection conn;rn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_main);rnrn new Thread()rn @Overridern public void run() rn try rn Class.forName("com.mysql.jdbc.Driver");rn conn = DriverManager.getConnection("jdbc:mysql://rm-bp1p408m8ey1z7ndv4o.mysql.rds.aliyuncs.com/mysql_data", "myroot", "Kwkx12345678");rn System.err.println(conn);rn catch (ClassNotFoundException e) rn e.printStackTrace();rn catch (SQLException e) rn e.printStackTrace();rn rn rn .start();rn rnrn rn```rnrnLocat输出:rn![图片说明](https://img-ask.csdn.net/upload/201811/28/1543372019_611452.png)rn错误提示,百度上搜了一下也没有rnCaused by: java.lang.ClassNotFoundException: Didn't find class "java.sql.SQLType" on path: DexPathList[[zip file "/data/app/com.example.administrator.
tomcat下jdbc for mysql的怎么连不上啊?
我用的是mysql-connector-java-3.0.10-stable-bin.jarrn法一、不用设置classpathrn把该文件放到jdk\jre\lib\ext下,rn和tomcat\common\lib下;rn测试代码是rn<%@ page contentType="text/html;charset=gb2312" %>rn<%@ page import="java.sql.*" %>rn<%rnString sDBDriver = "com.mysql.jdbc.Driver"; rnString sConnStr = "jdbc:mysql://localhost/test";rnConnection Con = null;rnStatement Stmt = null;rnResultSet RS=null; rntry rnClass.forName(sDBDriver).newInstance(); rncatch(java.lang.ClassNotFoundException e)rnout.print("Connect to Database error: " + e.getMessage());rntryrnCon = DriverManager.getConnection(sConnStr,"root",""); rncatch(SQLException e)rnout.print(e.toString());rn%>rnrnrn结果显示:rnConnect to Database error: com.mysql.jdbc.Driverjava.sql.SQLException: No suitable driver rnrn法二、rn1、添加classpath:设置文件mysql-connector-java-3.0.10-stable-bin.jar的路径rn2、将该jar文件放到tomcat\common\librn测试代码和显示结果和法一相同rnrn两天了,还是没有连接成功,郁闷!rn我的jdbc for ms sql server2000设置就比较顺利rn是法一和法二设置有问题还是其他原因?rnrn
jdbc连接mysql~~~不知道为什么连不上~~痛苦
使用的驱动程序是mysql-connector-java-3.1.8-bin-g.jar,加进了classpathrnrnString url = "jdbc:mysql://localhost:3306/Forum";rnClass.forName("com.mysql.jdbc.Driver").newInstance();rncon = DriverManager.getConnection(url);rnrn可是运行是出错rnException in thread "main" java.lang.NoClassDefFoundError: org/aspectj/lang/Signaturern at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:164)rn at User.main(User.java:120)rnrn查了很多贴子,也试了,但是还连不上(T_T)~~~~rn各位好心的大侠~~,帮个忙吧~
天啊,我的JDBC为什么就连不上MySQL
JSP连接MYSQL好几天了,从来没连上过,JDBC文件也放在\Tomcat 5.0\common\lib里了,相应的环境变量也配置了,可还是报错。报错内容如下:rnHTTP Status 500 - rn--------------------------------------------------------------------------------rntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnjavax.servlet.ServletException: org/aspectj/lang/Signaturern org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)rn org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)rn org.apache.jsp._06_005f03_jsp._jspService(_06_005f03_jsp.java:100)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrnrnroot cause rnrnjava.lang.NoClassDefFoundError: org/aspectj/lang/Signaturern java.lang.Class.forName0(Native Method)rn java.lang.Class.forName(Class.java:141)rn org.apache.jsp._06_005f03_jsp._jspService(_06_005f03_jsp.java:64)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrnnote The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.rn--------------------------------------------------------------------------------rnrn这到底是怎么了,求救哇!
Android直连MySQL ,无法建立连接
学习用尝试直连mysql5.7n```n public void run() n Connection cn=null;n try n Class.forName("com.mysql.jdbc.Driver");n String url="jdbc:mysql://IP:Port/db";n String user="root";n String password="123456";n cn= DriverManager.getConnection(url,user,password);n //程序执行到这一步抛出异常n if(cn!=null)n Log.e("ccc","cccc");n String sql="select B_Name from book";nn Statement st=(Statement)cn.createStatement();n ResultSet rs=st.executeQuery(sql);n while(rs.next())n String mybook=rs.getString("B_Name");n Log.e("Mainactivity",mybook);n n cn.close();n st.close();n rs.close();n catch (ClassNotFoundException e) n e.printStackTrace();n catch (SQLException e) n e.printStackTrace();n n n ).start();nn```nn![jar包](https://img-ask.csdn.net/upload/201805/20/1526829805_810045.png)n nn服务器的MySQL57服务开着, IP、Port、User和Password我都用Navicat测过,有效。排查下来不知道问题可能出在哪里。
jdbc直连,连接无法关闭!
package com.softtone.excution;rnrnimport java.sql.*;rnimport java.util.List;rnrnpublic class Odb rnrn String driverClassName = null;rn String URL = null;rn String username = null;rn String password = null;rn Connection mycon = null;rn ResultSet rs=null;rn Statement statement=null ; rn /**rn * @param driverClassNamern * @param urlrn * @param usernamern * @param passwordrn */rn rn public Odb()rn driverClassName = "com.ibm.db2.jcc.DB2Driver";rn URL = "jdbc:db2://202.112.107.114:3700/wapsite";rn username = "db2inst";rn password = "db2inst";rn rn public Odb(String dbip,String dbport,String dbname,String username,String password)rn rn this.driverClassName = "COM.ibm.db2.jcc.DB2Driver";rn this.URL = "jdbc:db2://"+dbip+":"+dbport+"/"+dbname+"";rn this.username = username; rn this.password = password; rn rn rnrn /**rn * 返回一个数据库的连接。rn */rn public Connection getConnection() rn tryrn Driver driver=null;rn driver = (Driver)Class.forName(driverClassName).newInstance();rn DriverManager.registerDriver(driver);rn mycon = DriverManager.getConnection(URL,username,password);// 数据源连接信息rnrn mycon.setAutoCommit(false);rn System.out.println("CONN OPENED");rn return mycon;rn rn catch (Exception e)rn close();rn e.printStackTrace();rn throw new RuntimeException(e);rn rn rn public Connection getAConnection()rn tryrn if (mycon==null)rn return getConnection();rn elsern return mycon;rn rn catch (Exception e) rn // TODO 自动生成 catch 块rn e.printStackTrace();rn throw new RuntimeException(e);rn rn rn rn /**rn * 查询数据库,返回一个ResultSet结果集。rn */rn public ResultSet query(String sql)rn tryrn getAConnection();rn statement = mycon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);rn rs=statement.executeQuery(sql);rn catch(SQLException ex)rn System.err.println("query():"+ex.getMessage());rn System.err.println("SQL:"+sql);rn throw new RuntimeException(ex);rn catch (Exception e) rn // TODO 自动生成 catch 块rn e.printStackTrace();rn throw new RuntimeException(e);rn rn return rs;rn rnrnrn rn /**rn * 执行单条sql语句。rn */rn public boolean excute(String sql)rn rn tryrn rn getAConnection();rn statement = mycon.createStatement();rn statement.execute(sql);rn mycon.commit();//提交rn rn return true;rn rn catch(SQLException ex) rn rn System.err.println("query():"+ex.getMessage());rn rn return false;rn catch (Exception e) rn // TODO 自动生成 catch 块rn e.printStackTrace();rn rn return false;rn rnrn rn rn /**rn * 批量执行sql语句。rn */rn public boolean excute(List sql) throws SQLExceptionrn rn tryrn rn try rn rn getAConnection();rn rn catch (Exception e) rn rn // TODO 自动生成 catch 块rn e.printStackTrace();rn// close();rn rn mycon.setAutoCommit(false);rn statement = mycon.createStatement();rn //System.out.println("进到这里了吗??");rn for(int i=0;i
通过jdbc连接mysql的怪事~~~
mysql3.23:rnroot口令设为空或者1111,通过jdbc连接均可成功;rnmysql4.12:rnroot口令设为空,通过jdbc连接可成功;如其口令不如空,假设为1111,则连接失败。他的口令偶是通过MySQL Control Center官方软件修改的,在MySQL Control Center配置好后输入口令1111,则连接成功;唯独通过jdbc口令不为空时连接失败,怪哉!rn那位兄弟请解疑,先谢过!rnrnps:程序绝无问题,偶以前给客户做的软件,用了一年多了
通过JDBC 连接MySQL问题
1.开始JAVA项目用JDBC连接MySQL时   无法连接成功  提示驱动加载异常    网友回答有   jar包位置不对    jdk环境变量配置有问题   jar包版本过低    最终解决的方法是  重新下载了一个版本的jar包 添加到了新建lib文件夹下最终成功连接   这里是jar包地址链接:http://pan.baidu.com/s/1boh2xOV 密码:h0tj
PB11.5 通过JDBC连接MySQL
PB11.5 通过JDBC连接MySQL,连接包:mysql-connector-java-5.1.28.jar
通过JDBC对MySQL的操作
业务分析 1. 连接数据库。 2. 对数据库进行操作。 代码实现(增、改、删) package cn.itcast.demo1; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql...
JDBC直连驱动程序库文件.rar
该文件是JAVA WEB编程中解决SQL Server 2000中直连问题的程序包,为数据库直连提供了良好的功能
JDBC直连数据库的一般方法
JDBC直连数据库的一般方法,java连接数据库,数据库连接,java怎么连接数据库,方法直通车!手把手教你连接数据库!
连不上mysql?
错误: 不能连接MySQL服务器: "localhost" : '' MySQL系统报告:Client does not support authentication protocol requested by server; consider upgrading MySQL client rn以上这个错误怎么处理?rn我装了Mysql server 4.1 用root用户来连接!
server2000 jdbc 直连驱动包
server2000 jdbc 直接 驱动包 3个 我的别的分那么低,你们还说我黑,这次我就黑一次,把这三个驱动包导入到你的服务器上就好
Hibernate居然JDBC连不上
各种配置都弄好了,Hibernate 3的那些库都加上了,SqlServer的3个Jar也加了,msbase.jar,mssqlserver.jar,msutil.jarrnrn现在写了个简单的代码测试session创建rnrn[code=Java]rn org.hibernate.SessionFactory sessionFactory = new org.hibernate.cfg.rn Configuration().configure().buildSessionFactory();rn org.hibernate.Session session = sessionFactory.openSession();rn System.out.println("----------qry1----------");rn org.hibernate.Query qry = session.createQuery("from FriendBean");rn java.util.List list = qry.list();rn for (int i = 0; i < list.size(); i++) rn FriendBean frdTest = (FriendBean) list.get(i);rn System.out.println(frdTest.getName());rn rn[/code]rnrncfg配置文件是这么写的rnrn[code=XML]rnrnrnrn rn rn com.microsoft.jdbc.sqlserver.SQLServerDriverrn jdbc:sqlserver://localhost\BWL:1433;DatabaseName=Friendsrn sarn biweilunrn rn 5rn rn org.hibernate.dialect.SQLServerDialectrn rn threadrn rn org.hibernate.cache.NoCacheProviderrn rn truern rn rnrnrn[/code]rnrn运行就抛连接异常rnrnlog4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).rnlog4j:WARN Please initialize the log4j system properly.rn----------qry1----------rnException in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connectionrn at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)rn at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)rn at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)rn at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)rn at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)rn at org.hibernate.loader.Loader.doQuery(Loader.java:661)rn at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)rn at org.hibernate.loader.Loader.doList(Loader.java:2145)rn at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)rn at org.hibernate.loader.Loader.list(Loader.java:2024)rn at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)rn at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)rn at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)rn at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)rn at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)rn at hibernatetask.Main.main(Main.java:31)rnCaused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.rn at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)rn at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn at com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)rn at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)rn at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)rn at java.sql.DriverManager.getConnection(DriverManager.java:582)rn at java.sql.DriverManager.getConnection(DriverManager.java:154)rn at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)rn at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)rn ... 14 morernJava Result: 1rn成功生成(总时间:13 秒)rn
JDBC驱动连不上SQL2000
jsp里调用BEAN jbuilder+weblogic8.1.3rnrnJBUILDER显示错误:knowRows() 驱动不匹配rn*************************************************************rnrnpackage netconfig;rnimport java.sql.*;rnrnpublic class Bean2 rn private String msDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";rn private String msUrl="jdbc:microsoft:sqlserver://192.168.0.1:1433;databasename=opti,sa,sa";rn private Connection mCon=null;rn private Statement mStmt=null;rn private ResultSet mRs=null;rn /*注册数据库驱动程序*/rn public Bean2() rn try rn Class.forName(msDBDriver);rn rn catch(java.lang.ClassNotFoundException e) rn System.out.println("Bean2(): "+e.getMessage());rn e.printStackTrace();rn rn rnrn /*定义查询*/rn public ResultSet executeQuery(String sql)rn mRs=null;rn tryrn //创建数据库连接对象rn mCon=DriverManager.getConnection(msUrl,"sa","sa");rn mStmt=mCon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);rn mRs=mStmt.executeQuery(sql);rn rn catch(SQLException sqle)rn System.out.println("executeQuery(): "+sqle.getMessage());rn rn return mRs;rn rnrn /*定义数据库操作*/rn public void executeUpdate(String sql)rn mStmt=null;rn mRs=null;rn tryrn //创建数据库连接对象rn mCon=DriverManager.getConnection(msUrl,"sa","sa");rn mStmt=mCon.createStatement();rn mStmt.executeUpdate(sql);rn mStmt.close();rn mCon.close();rn rn catch(SQLException sqle)rn System.out.println("excuteUpdate(): "+sqle.getMessage());rn rn rnrn /*返回记录集总数*/rn public long knowRows(String sql)rn long lrows=0;rn mRs=null;rn tryrn mCon=DriverManager.getConnection(msUrl,"sa","sa");rn mStmt=mCon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);rn //mStmt=mCon.createStatement();rn mRs=mStmt.executeQuery(sql);rn mRs.first();rn //得到记录总数rn lrows=mRs.getLong("rows");rn rn catch(SQLException sqle)rn System.out.println("knowRows(): "+sqle.getMessage());rn rn return lrows;rn rnrn /*关闭数据库连接*/rn public void closeRs()rn try rn mRs.close();rn rn catch (SQLException e) rn e.printStackTrace();rn rn rn public void closeStmt()rn tryrn mStmt.close();rn rn catch(SQLException e)rn e.printStackTrace();rn rn rn public void closeCon()rn tryrn mCon.close();rn rn catch(SQLException e)rn e.printStackTrace();rn rn rn rn
jdbc 连不上数据库问题求教
问题描述如下:rn1.数据库服务器是三网卡的,防火墙已开通。rn2. web 服务器是 Linux,web 容器是 was 8.5rn3.web 服务器上tnsping 数据库tns能通,telnent host port 也能通。rn4. was上配的 jdbc数据源连上不数据库,代码中的的jdbc也连上不数据库。rn5.返回无法建立连接。socket 超时
如何用JDBC直连数据库?
我已经把三个jar包加到CLASSPATH中了,rnClass.forname("com.microsoft.jdbc.sqlserver.SQLServerDriver");rncon = DriverManager.creatconnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;datavaseName=pubs","sa","sa")rn总是出noclassfound之类的异常,就是因为这个考试都没过
JDBC连不上oracle了
控制台提示:rnjava.sql.SQLException: Io 异常: The Network Adapter could not establish the connectionrn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)rn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:190)rn at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:363)rn at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)rn at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:441)rn at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)rn at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)rn at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:839)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at java.sql.DriverManager.getConnection(Unknown Source)rn at wf.common.DBUtil.getConnection(DBUtil.java:16)rn at wf.traffic.TrafficBP.getCarnumber(TrafficBP.java:17)rn at wf.traffic.TrafficServlet.doGet(TrafficServlet.java:26)rn at wf.traffic.TrafficServlet.doPost(TrafficServlet.java:34)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)rn at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)rn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)rn at java.lang.Thread.run(Unknown Source)rnrn页面上是exception rnrnjava.lang.NullPointerExceptionrn wf.traffic.TrafficBP.getCarnumber(TrafficBP.java:41)rn wf.traffic.TrafficServlet.doGet(TrafficServlet.java:26)rn wf.traffic.TrafficServlet.doPost(TrafficServlet.java:34)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:709)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn
连不上mysql
一连接mysql就不行rn用的语句是rnrn$db=mysql_connect('localhost','root','password');rnrn一执行到这句网页就直接http500内部服务器错误了。什么提示也没有。试了N多遍了老是不行rnrn在dos下进入mysql一切正常rnrnphp.ini里面extension=php_mysql.dll和php_mysqli.dll都选了 apache的设置也没有问题rnrn是哪里出错了?
用pb直连MSS数据库接口为什么连不上?
-
Android通过JDBC连接MySql数据库
Android通过JDBC连接MySql数据库 android中联网访问权限的添加 AndroidManifest文件中要添加权限 ... </application> <uses-permission android:name="android.permission.INTERNET" /> </manifest>关闭Windows防火墙 (点击控制面板, 进入之后在控制面板中找到
android通过JDBC连接Mysql数据库
android通过JDBC连接Mysql数据库,并将查询结果显示在android手机上.
相关热词 c++和c#哪个就业率高 c# 批量动态创建控件 c# 模块和程序集的区别 c# gmap 截图 c# 验证码图片生成类 c# 再次尝试 连接失败 c#开发编写规范 c# 压缩图片好麻烦 c#计算数组中的平均值 c#获取路由参数