mycat 做mysql中间件问题

MySql 码拜 8年前 (2016-01-30) 1013次浏览
mycat 做mysql中间件
命令行 可以连接上,
程序无法连接
命令行如下图mycat 做mysql中间件问题
程序代码:

package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DbConnectionTest {
	private static String url = "jdbc:mysql://192.168.1.212:8066/TESTDB?useUnicode=true&characterEncoding=utf-8";
	private static String username = "test";
	private static String password = "test";
	private static String driverName = "com.mysql.jdbc.Driver";
	public DbConnectionTest() {
		super();
		// TODO Auto-generated constructor stub
	}
	static {
		try {
			Class.forName(driverName);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, username, password);
	}
	public static void close(ResultSet rs, Statement st, Connection conn) {
		try {
			if (rs != null) {
				rs.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (st != null) {
					st.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				if (conn != null) {
					try {
						conn.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}
	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			conn = getConnection();
			String sql = "select * from testaaaaa";
			ps = conn.prepareStatement(sql);
//			ps.setString(1, "psName");
//			ps.setString(2, "psPassword");
//			ps.setString(3, "jkjs@126.com");
//			ps.setInt(4, 23);
//			ps.setDate(5, new java.sql.Date(new java.util.Date().getDate()));
//			ps.setFloat(6, 2344);
			rs = ps.executeQuery(sql);
			while(rs.next()){
				System.out.println(rs.getString("name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(rs, ps, conn);
		}
	}
}

mycat 做mysql中间件问题


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明mycat 做mysql中间件问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)