当前位置: 技术问答>java相关
我是菜鸟,想要个oracle数据库操作 的例子
来源: 互联网 发布时间:2015-05-11
本文导语: 我是菜鸟,想要个oracle数据库操作 的例子,各位帮帮忙了 | import java.sql.*; public class db_test { public static void main(String args[]) { try { String s_server_ip="192.168.1.243"; String s_ser...
我是菜鸟,想要个oracle数据库操作 的例子,各位帮帮忙了
|
import java.sql.*;
public class db_test
{
public static void main(String args[])
{
try
{
String s_server_ip="192.168.1.243";
String s_service_name="mydb";
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String s_url = "jdbc:oracle:thin:@"+s_server_ip+":1521:"+s_service_name;
String s_userName="myuserName";
String s_passWord="passwd";
Connection conn = DriverManager.getConnection(s_url,s_userName,s_passWord);
Statement stmt=conn.createStatement();
String s_sql="SELECT * FROM ontimeday";
ResultSet rs=stmt.executeQuery(s_sql);
while (rs.next())
{
System.out.println("ONTIMEID:"+rs.getInt(1)+" USER_ID:"+rs.getInt(2)+" URLNAME:"+rs.getString(3));
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
} //end main
}
public class db_test
{
public static void main(String args[])
{
try
{
String s_server_ip="192.168.1.243";
String s_service_name="mydb";
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String s_url = "jdbc:oracle:thin:@"+s_server_ip+":1521:"+s_service_name;
String s_userName="myuserName";
String s_passWord="passwd";
Connection conn = DriverManager.getConnection(s_url,s_userName,s_passWord);
Statement stmt=conn.createStatement();
String s_sql="SELECT * FROM ontimeday";
ResultSet rs=stmt.executeQuery(s_sql);
while (rs.next())
{
System.out.println("ONTIMEID:"+rs.getInt(1)+" USER_ID:"+rs.getInt(2)+" URLNAME:"+rs.getString(3));
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
} //end main
}