Topic: 新手求助:jdbc连接mysql的问题

  Print this page

1.新手求助:jdbc连接mysql的问题 Copy to clipboard
Posted by: koala74
Posted on: 2005-03-27 12:02

我用jbuilder X做一个操作mysql数据库的例子,按要求添加了类库mysql-connector-java-3.1.7-bin.jar。
能够连接数据库和创建新表,但是在做插入记录时总不能实现。
代码如下:
---DataJDBC.java---
package databasepro;
import java.sql.*;
public class DataJDBC{
String driver="org.gjt.mm.mysql.Driver";
String url="jdbc:mysql://localhost:3306/mysqldemo?user=root;password=";
Connection conn = null;
public DataJDBC() {
try{
Class.forName(driver);
conn=DriverManager.getConnection(url);
}catch(Exception ex){
ex.printStackTrace();
}
}
public Connection getConn(){
return conn;
}
}
---Tablecreat.jsp---
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import ="java.sql.*"%>
<html>
<head>
<title>
Tablecreat 实例
</title>
</head>
<jsp:useBean id="dataBean" class="databasepro.DataJDBC"/>
<body bgcolor="#ffffff">
<h1>
JBuilder Generated JSP
</h1>
<h3>
<%
Connection conn=dataBean.getConn();
Statement stmt=conn.createStatement();
/*String sql="Create table tabledemo2("+
"id int primary key auto_increment,"+
"title varchar(100),"+
"content text);";
try{
stmt.execute(sql);
out.println("<p>成功创建demo2</p>");
}catch(Exception ex){
out.print("<p>已经创建demo2</p>"); }
*/
int i=0;
for(i = 1; i < 7 ; i++)
{
String insertStr="insert into tabldemo2(title,content) values('记录"+i+"','内容"+i+"');";
try{
stmt.execute(insertStr);
out.println("<p>成功插入记录"+i+".</p>");
}catch(Exception ex){
out.print("<p>插入记录失败。</p>"); }
}
%>
</h3>
</body>
</html>
注释掉的内容执行成功后直接修改原文件进行插入记录,即使直接插入一条记录也失败。weblogic出现一条错误,如何解决?
<2005-3-27 下午12时03分19秒 CST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 8.1 Thu Mar 20 23:06:05 PST 2003 246620
WebLogic XMLX Module 8.1 Thu Mar 20 23:06:05 PST 2003 246620 >

<2005-3-27 下午12时03分20秒 CST> <Notice> <Management> <BEA-140005> <Loading domain configuration from configuration repository at D:\bea\user_projects\mydomain\.\config.xml.>

<2005-3-27 下午12时03分27秒 CST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.>

<2005-3-27 下午12时03分27秒 CST> <Notice> <WebLogicServer> <BEA-000327> <Starting WebLogic Admin Server "myserver" for domain "mydomainr">

<2005-3-27 下午12时03分30秒 CST> <Warning> <Management> <BEA-149317> <Application JBuilder_WebRun is configured with a deprecated deployment protocol and will be deployed as such.>

<2005-3-27 下午12时03分31秒 CST> <Warning> <HTTP> <BEA-101296> <Unable to load the default compiler class "com.sun.tools.javac.Main". Using the default javac compiler to compile JSPs.>

<2005-3-27 下午12时03分34秒 CST> <Error> <JDBC> <BEA-001150> <Connection Pool "cajunPool" deployment failed with the following error: Cannot load driver class: com.pointbase.jdbc.jdbcUniversalDriver.>

<2005-3-27 下午12时03分37秒 CST> <Notice> <WebLogicServer> <BEA-000355> <Thread "ListenThread.Default" listening on port 7001, ip address *.*>

<2005-3-27 下午12时03分37秒 CST> <Notice> <WebLogicServer> <BEA-000331> <Started WebLogic Admin Server "myserver" for domain "mydomainr" running in Development Mode>

<2005-3-27 下午12时03分37秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING>

<2005-3-27 下午12时03分37秒 CST> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode>


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923