jdbc连接oracle怎么连接不上啊
packagecom.cl.ch;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sq...
package com.cl.ch;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
public class TestJDBC {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//建立连接对象
Connection conn=null;
try {
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",
"scott","tiger");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//建立可以执行sql语句的Statement对象
Statement st=null;
try {
st=conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//执行查询,得到ResultSet类型的结果集合
ResultSet set=null;
try {
set=st.executeQuery("select empno eno,ename,deptno,sal,hiredate from emp");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//解析数据
try {
while(set.next()){
int empno=set.getInt("eno");
String ename=set.getString(2);
int deptno=set.getInt(3);
double sal=set.getDouble(4);
Date hiredate=set.getDate(5);
System.out.println(empno+"\t"+ename+"t"+deptno+"\t"+sal+"t"+hiredate);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}if(set!=null){
try {
set.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(st!=null){
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
提示的错误是 展开
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
public class TestJDBC {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//建立连接对象
Connection conn=null;
try {
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",
"scott","tiger");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//建立可以执行sql语句的Statement对象
Statement st=null;
try {
st=conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//执行查询,得到ResultSet类型的结果集合
ResultSet set=null;
try {
set=st.executeQuery("select empno eno,ename,deptno,sal,hiredate from emp");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//解析数据
try {
while(set.next()){
int empno=set.getInt("eno");
String ename=set.getString(2);
int deptno=set.getInt(3);
double sal=set.getDouble(4);
Date hiredate=set.getDate(5);
System.out.println(empno+"\t"+ename+"t"+deptno+"\t"+sal+"t"+hiredate);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}if(set!=null){
try {
set.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(st!=null){
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
提示的错误是 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询