当前位置: 技术问答>java相关
谁告诉我错在哪里,为什么不行,我送1000分~!
来源: 互联网 发布时间:2015-11-01
本文导语: import java.io.*; import java.util.*; import java.sql.*; public class connection { String driver = ""; String url = ""; String user = ""; String password = ""; Connection con; Statement stmt = null; Statem...
import java.io.*;
import java.util.*;
import java.sql.*;
public class connection {
String driver = "";
String url = "";
String user = "";
String password = "";
Connection con;
Statement stmt = null;
Statement stmt1 = null;
String no;
CallableStatement cstmt;
/**
* Constructor for the connection object
* 设置连接字符串(oracle)
*/
public connection()
{
InputStream is = getClass().getResourceAsStream("/db.properties");
Properties prop = new Properties();
try {
prop.load(is);
if (is != null)
is.close();
}
catch (IOException e) {
System.out.println("打开文件时出错");
}
driver = prop.getProperty("driver");
url = prop.getProperty("url");
user = prop.getProperty("user");
password = prop.getProperty("password");
}
/**
* 连接数据库
*
*@exception ClassNotFoundException 数据库连接桥未找到
*@exception SQLException 数据库连接异常
*/
public void createconnection()
throws ClassNotFoundException, SQLException {
try {
Class.forName(driver);
if (Debug.DEBUG) {
System.out.println("1==============================" + url);
}
con = DriverManager.getConnection(url, user, password);
if (Debug.DEBUG) {
System.out.println("2==============================");
}
} catch (ClassNotFoundException e) {} catch (SQLException e) {
System.out.println("连接失败!");
}
try {
stmt = con.createStatement();
if (Debug.DEBUG) {
System.out.println("3==============================");
}
stmt1 = con.createStatement();
if (Debug.DEBUG) {
System.out.println("4==============================");
}
} catch (SQLException e) {}
}
/**
* create Statement
*
*@return Statement
*/
public Statement createStatement() {
try {
return con.createStatement();
} catch (SQLException e) {
System.out.println("Statement has problem!");
return null;
}
}
/**
* create Statement 有参数
*
*@param resultSetType 返回 resultSet 类型
*@param resultSetConcurrency 并发
*@return Statement
*/
public Statement createStatement(int resultSetType, int resultSetConcurrency) {
try {
return con.createStatement(resultSetType, resultSetConcurrency);
} catch (SQLException e) {
return null;
}
}
/**
* 数据库查询 有参数
*
*@param query 查询字符串
*@return ResultSet
*/
public ResultSet executeQuerySearch(String query) {
ResultSet rs;
try {
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(query);
} catch (SQLException sqlex) {
return null;
}
return rs;
}
/**
* Callable Statement
*
*@param sql 查询字符串
*@return CallableStatement
*/
public CallableStatement prepareCall(String sql) {
try {
return con.prepareCall(sql);
} catch (SQLException e) {
return null;
}
}
/**
* Gets the autoCommit attribute of the connection object
*
*@return The autoCommit value
*@exception SQLException sql异常
*/
public boolean getAutoCommit()
throws SQLException {
return con.getAutoCommit();
}
/**
* Sets the autoCommit attribute of the connection object
*
*@param autoCommit The new autoCommit value
*@exception SQLException sql异常
*/
public void setAutoCommit(boolean autoCommit)
throws SQLException {
con.setAutoCommit(autoCommit);
}
/**
* 提交
*
*@exception SQLException sql异常
*/
public void commit() throws SQLException {
con.commit();
}
/**
* Description of the Method
*
*@exception SQLException sql异常
*/
public void rollback() throws SQLException {
con.rollback();
}
/**
* Gets the connection attribute of the connection object
*
*@return The connection value
*/
public Connection getConnection() {
return con;
}
/**
* 关闭数据库连接
*/
public void close() {
try {
if (!con.getAutoCommit()) {
con.setAutoCommit(true);
}
con.close();
} catch (SQLException e) {
}
}
}
import java.util.*;
import java.sql.*;
public class connection {
String driver = "";
String url = "";
String user = "";
String password = "";
Connection con;
Statement stmt = null;
Statement stmt1 = null;
String no;
CallableStatement cstmt;
/**
* Constructor for the connection object
* 设置连接字符串(oracle)
*/
public connection()
{
InputStream is = getClass().getResourceAsStream("/db.properties");
Properties prop = new Properties();
try {
prop.load(is);
if (is != null)
is.close();
}
catch (IOException e) {
System.out.println("打开文件时出错");
}
driver = prop.getProperty("driver");
url = prop.getProperty("url");
user = prop.getProperty("user");
password = prop.getProperty("password");
}
/**
* 连接数据库
*
*@exception ClassNotFoundException 数据库连接桥未找到
*@exception SQLException 数据库连接异常
*/
public void createconnection()
throws ClassNotFoundException, SQLException {
try {
Class.forName(driver);
if (Debug.DEBUG) {
System.out.println("1==============================" + url);
}
con = DriverManager.getConnection(url, user, password);
if (Debug.DEBUG) {
System.out.println("2==============================");
}
} catch (ClassNotFoundException e) {} catch (SQLException e) {
System.out.println("连接失败!");
}
try {
stmt = con.createStatement();
if (Debug.DEBUG) {
System.out.println("3==============================");
}
stmt1 = con.createStatement();
if (Debug.DEBUG) {
System.out.println("4==============================");
}
} catch (SQLException e) {}
}
/**
* create Statement
*
*@return Statement
*/
public Statement createStatement() {
try {
return con.createStatement();
} catch (SQLException e) {
System.out.println("Statement has problem!");
return null;
}
}
/**
* create Statement 有参数
*
*@param resultSetType 返回 resultSet 类型
*@param resultSetConcurrency 并发
*@return Statement
*/
public Statement createStatement(int resultSetType, int resultSetConcurrency) {
try {
return con.createStatement(resultSetType, resultSetConcurrency);
} catch (SQLException e) {
return null;
}
}
/**
* 数据库查询 有参数
*
*@param query 查询字符串
*@return ResultSet
*/
public ResultSet executeQuerySearch(String query) {
ResultSet rs;
try {
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(query);
} catch (SQLException sqlex) {
return null;
}
return rs;
}
/**
* Callable Statement
*
*@param sql 查询字符串
*@return CallableStatement
*/
public CallableStatement prepareCall(String sql) {
try {
return con.prepareCall(sql);
} catch (SQLException e) {
return null;
}
}
/**
* Gets the autoCommit attribute of the connection object
*
*@return The autoCommit value
*@exception SQLException sql异常
*/
public boolean getAutoCommit()
throws SQLException {
return con.getAutoCommit();
}
/**
* Sets the autoCommit attribute of the connection object
*
*@param autoCommit The new autoCommit value
*@exception SQLException sql异常
*/
public void setAutoCommit(boolean autoCommit)
throws SQLException {
con.setAutoCommit(autoCommit);
}
/**
* 提交
*
*@exception SQLException sql异常
*/
public void commit() throws SQLException {
con.commit();
}
/**
* Description of the Method
*
*@exception SQLException sql异常
*/
public void rollback() throws SQLException {
con.rollback();
}
/**
* Gets the connection attribute of the connection object
*
*@return The connection value
*/
public Connection getConnection() {
return con;
}
/**
* 关闭数据库连接
*/
public void close() {
try {
if (!con.getAutoCommit()) {
con.setAutoCommit(true);
}
con.close();
} catch (SQLException e) {
}
}
}
|
出错信息?你要做什么?
|
会不会你的配置信息取不到 路径不对??
真的没出错信息 看不出来
真的没出错信息 看不出来
|
嗨,先不说你的代码那么长,根本就没有心情去看完
而且是哪儿出错,什么错误都不给出,你让咱怎么帮你解决呢
而且是哪儿出错,什么错误都不给出,你让咱怎么帮你解决呢
|
单纯的讲,程序本身并没有错误,我不知道,你哪里出问题了,是不是路径不对,或别的什么?
|
如何不行了?
|
9494,先把问题说清楚。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。