jsp+Oracle求指导
<%@pagecontentType="text/html;charset=gb2312"%><%@pagelanguage="java"%><%@pageimport=...
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%
//连接字符串
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //不同机器上oracle10g的数据库实 例名不同,作相应修改。
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String user="system";//数据库的用户名
String password="oracle";//注意数据库密码的差异
//连接数据库
Connection connection= DriverManager.getConnection(url,user,password);
Statement statement = connection.createStatement();
String sql="SELECT * FROM mytable";
ResultSet rs = statement.executeQuery(sql); //执行sql语句
// 输出每一个数据值
out.print("uername");
out.print("|");
out.print("email");
out.print("|");
out.print("tel");
out.print("<br>");
//输出数据库中指定属性值
while(rs.next()) {
out.print(rs.getString(1)+" ");
out.print("|");
out.print(rs.getString(3));
out.print("|");
out.print(rs.getString(4));
out.print("<br>");
}
out.print("<br>");
out.print("数据库操作成功,恭喜你");
%>
<body>
<input name="name" type="text" value="" size="30">
<input name="button" type="button" value=" 提 交 " onClick="isValid()" >
<%
String mytable_username=new String(request.getParameter("name").getBytes("8859_1"));
try
{
String sql = "insert into mytable(mytable_username,mytable_password,mytable_email,mytable_tel) values(?,?,?,?)";
ps.setString(1,mytable_username);
%></body>
连接数据库 要写入一个数据 就随手做了个简单的 但是MyEclipse报错 求解 展开
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%
//连接字符串
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //不同机器上oracle10g的数据库实 例名不同,作相应修改。
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String user="system";//数据库的用户名
String password="oracle";//注意数据库密码的差异
//连接数据库
Connection connection= DriverManager.getConnection(url,user,password);
Statement statement = connection.createStatement();
String sql="SELECT * FROM mytable";
ResultSet rs = statement.executeQuery(sql); //执行sql语句
// 输出每一个数据值
out.print("uername");
out.print("|");
out.print("email");
out.print("|");
out.print("tel");
out.print("<br>");
//输出数据库中指定属性值
while(rs.next()) {
out.print(rs.getString(1)+" ");
out.print("|");
out.print(rs.getString(3));
out.print("|");
out.print(rs.getString(4));
out.print("<br>");
}
out.print("<br>");
out.print("数据库操作成功,恭喜你");
%>
<body>
<input name="name" type="text" value="" size="30">
<input name="button" type="button" value=" 提 交 " onClick="isValid()" >
<%
String mytable_username=new String(request.getParameter("name").getBytes("8859_1"));
try
{
String sql = "insert into mytable(mytable_username,mytable_password,mytable_email,mytable_tel) values(?,?,?,?)";
ps.setString(1,mytable_username);
%></body>
连接数据库 要写入一个数据 就随手做了个简单的 但是MyEclipse报错 求解 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询