JAVA连接oracle的接字符串是怎么样的?
麻烦各位把具体步骤以及每个参数的意思说一下~~初学oracle,请各位多多指教!localhost:1521//这里的1521是服务器端口吗?下面user和passwor...
麻烦各位把具体步骤以及每个参数的意思说一下~~初学oracle,请各位多多指教!
localhost:1521//这里的1521是服务器端口吗?
下面user和password是可以用sys或者自己创建的用户吗? 展开
localhost:1521//这里的1521是服务器端口吗?
下面user和password是可以用sys或者自己创建的用户吗? 展开
5个回答
展开全部
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package com.ultrapower.util;
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 ConnectionUtil {
public static Connection connection = null;
public ConnectionUtil(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(ClassNotFoundException ex){
System.out.println(getErrorMessage(ex,"The Driver loaded error,please contact to your Software Designer").toString());
}
}
public Connection getConnection(){
try{
if(null == connection){
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr");
}
}catch(Exception ex){
//System.out.println(getErrorMessage(ex,"Can not get connection,please contact to your Software Designer!"));
}
return connection;
}
public void colseConnection(Connection connection,Statement smt){
try{
smt.close();
connection.close();
}catch(SQLException ex){
System.out.println(getErrorMessage(ex,"close statement or connection exception!"));
}
}
public StringBuffer getErrorMessage(Exception ex,String alarmMessage){
StringBuffer errorStringBuffer = new StringBuffer();
errorStringBuffer.append(alarmMessage);
errorStringBuffer.append(ex.getMessage());
return errorStringBuffer;
}
public static void main(String[] args){
ConnectionUtil cu = new ConnectionUtil();
Connection c = cu.getConnection();
PreparedStatement ps;
try {
ps = c.prepareStatement("select * from staff");
ResultSet rs = ps.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
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 ConnectionUtil {
public static Connection connection = null;
public ConnectionUtil(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(ClassNotFoundException ex){
System.out.println(getErrorMessage(ex,"The Driver loaded error,please contact to your Software Designer").toString());
}
}
public Connection getConnection(){
try{
if(null == connection){
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr");
}
}catch(Exception ex){
//System.out.println(getErrorMessage(ex,"Can not get connection,please contact to your Software Designer!"));
}
return connection;
}
public void colseConnection(Connection connection,Statement smt){
try{
smt.close();
connection.close();
}catch(SQLException ex){
System.out.println(getErrorMessage(ex,"close statement or connection exception!"));
}
}
public StringBuffer getErrorMessage(Exception ex,String alarmMessage){
StringBuffer errorStringBuffer = new StringBuffer();
errorStringBuffer.append(alarmMessage);
errorStringBuffer.append(ex.getMessage());
return errorStringBuffer;
}
public static void main(String[] args){
ConnectionUtil cu = new ConnectionUtil();
Connection c = cu.getConnection();
PreparedStatement ps;
try {
ps = c.prepareStatement("select * from staff");
ResultSet rs = ps.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
oralce 9i的 url 是这个jdbc:oracle:thin:@*.*.*.*:1521:ORA92I
驱动是 oracle.jdbc.driver.OracleDriver
这样回答 你应该明白怎么用了吧
驱动是 oracle.jdbc.driver.OracleDriver
这样回答 你应该明白怎么用了吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个最好在配置文件里配置
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Connection conn=DriverManager.getConnection(strUrl,sqlusername,sqlpassword);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询