日期:2014-05-17 浏览次数:20917 次
package com.hsp.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBUtils {
private static Connection ct = null;
private static PreparedStatement ps = null;
private static ResultSet rs = null;
public Connection getConn(){
String username = "scott";
String passwd = "duanhaibin";
String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
ct = DriverManager.getConnection(url,username,passwd);
} catch (Exception e) {
e.printStackTrace();
}
return ct;
} //这里报Multiple markers at this line - Syntax error on token "}", { expected after this token
//怎么回事呀。
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ct != null) {
try {
ct.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}