新人求助,代码出错了

代码如下:

#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define SIZE 20
typedef FILE *PFILE;
typedef char String[SIZE];
using namespace std;

typedef struct   //单词类型
{
    String data;//单词串
    int len;   //单词的长度
}WordType;

typedef struct WordNode    //单词结点类型
{
    WordType data;
    WordNode *next;
}WordNode, *PWordNode;

typedef struct RowLink     //表示文本每一行的链表
{
    WordNode *head, *tail;
}RowLink,*RLink;

typedef struct RowNumNode    //行号结点类型
{
    int elem;    //行号
    RowNumNode *next;
}RowNumNode,*RowNumLink;

typedef struct SearchWordNode    //带搜索的单词结点类型
{
    WordType data;        //待搜索单词
    int count;            //待搜索单词出现的次数
    RowNumLink RNhead, RNtail;    //存放文本中出现待搜索单词行号的链表
    SearchWordNode *next;
}SearchWordNode,*SWLink;

struct SWLinkList
{
    SWLink head,tail;
};

void CopyWord(WordType &w, String ch)    //把字符串ch复制到单词元素w
{
    int j = strlen(ch);
    for (int i = 0; i <= j; i++)
        w.data[i] = ch[i];
    w.len = j;
}

int MatchWord(WordType w1, WordType w2)    //单词的匹配,若相等则返回1,否则返回非0
{
    int i;
    if (w1.len != w2.len)
        return 0;
    else
    {
        for ( i = 0; i < w1.len; i++)
        {
            if (w1.data[i] != w2.data[i])
                break;
        }
        if ( i==w1.len)
            return 1;
        else
            return 0;
    }
}

void MakeWordNode(PWordNode &PN)    //生成一个单词结点
{
    if (!(PN = (PWordNode)malloc(sizeof(WordNode))))
    {
        cout << "为单词分配存储空间失败" << endl;
        exit(0);
    }
    PN->next = NULL;
}

void InsertAfter(RowLink &L, WordType w)    //用后插法把单词结点w插入链表L
{
    MakeWordNode(L.tail->next);
    L.tail->next->data = w;
    L.tail = L.tail->next;
}

void DestroyWordLink(RowLink &L)    //销毁链表L
{
    while (L.head)
    {
        L.tail = L.head->next;
        delete(L.head);
        L.head = L.tail;
    }
}

void CreateWordLink(RowLink &L, FILE *f)    //创建存放f指向文本中每一行单词的链表
{
    int i;
    String ch;
    char c = getc(f);    //从文件中读取一个字符
    WordType w;
    MakeWordNode(L.head);
    L.tail = L.head;
    while (c != '\n'&&!feof(f))
    {
        while (!(c >= 'A'&&c <= 'Z' || c >= 'a'&&c <= 'z') && c != '\n'&&!feof(f))    //滤去非法字符
            c = getc(f);
        for ( i = 0; c >= 'A'&&c <= 'Z' || c >= 'a'&&c <= 'z'; i++)    //取单词
        {
            ch[i] = c;
            c = getc(f);    
        }
        ch[i] = '\0';
        CopyWord(w, ch);
        InsertAfter(L, w);
    }
}

void MakeRowNumNode(RowNumLink &p)    //生成一个行结点
{
    if (!(p = (RowNumLink)malloc(sizeof(RowNumNode))))
    {
        cout << "分配行号结点失败" << endl;
        exit(0);
    }
    p->next = NULL;
}

void MakeSWNode(SWLink &p)    //生成一个待搜索的单词结点
{
    if (!(p = (SWLink)malloc(sizeof(SearchWordNode))))
    {
        cout << "分配待搜索的单词结点失败" << endl;
        exit(0);
    }
    p->next = NULL;
    p->count = 0;
    p->RNhead = NULL;
    p->RNtail = NULL;
}

void CreateSWLinkList(SWLinkList &S)    //建立一个待搜索的单词链表
{
    MakeSWNode(S.head);
    S.tail = S.head;
    String st = "#";
    WordType w, label;
    CopyWord(label, st);
    cout << "请输入要搜索的英文单词,输入完毕后请输入'#'结束输入" << endl;
    cin >> st;
    CopyWord(w, st);
    while (!MatchWord(w, label))    //w不是'#'
    {
        MakeSWNode(S.tail->next);
        S.tail->next->data = w;
        S.tail = S.tail->next;
        cin >> st;
        CopyWord(w, st);
    }
}

void MatchSWLinkList(SWLinkList &S, FILE *f)//查找文本中出现待搜索的单词
{
    RowLink RL;    //用于保存文件中一行单词的链表
    PWordNode pr = NULL;    //指向文件单次链表中的每一个单词
    SWLink ps = NULL;    //指向被搜索的单词
    int i = 0;
    while (!(feof(f)))    //读取文本中的每一行单词
    {
        i++;    //行号
        CreateWordLink(RL, f);    //创建文本的一行单词的链表
        ps = S.head->next;    //ps指向此时被搜索的单词
        while (ps)    //遍历待搜索的单词链表的每个结点,及当ps所指单词不为空,在本行中查找其出现次数
        {
            pr = RL.head->next;    //该指针指向文件该行的链表
            int label = 1;    //用于标志待搜索单词在本行中是否是第一次出现,若是须创建一行结点,若不是,直接count+1
            while (pr)       //文本中一行单词链表的每个结点依次与被搜索单词比较
            {
                if (MatchWord(pr->data, ps->data))
                {
                    ps->count++;
                    if (label == 1)     //是该正在搜索指针所指的
                    {
                        if (ps->RNhead == NULL)    //判断是否是第一个结点
                        {
                            MakeRowNumNode(ps->RNhead);    //创建统计被搜索单词出现次数及行号的链表
                            ps->RNhead->elem = i;
                            ps->RNtail = ps->RNhead;
                        }
                        else
                        {
                            MakeRowNumNode(ps->RNtail->next);
                            ps->RNtail->next->elem = i;
                            ps->RNtail = ps->RNtail->next;
                        }
                        label = 0;
                    }
                }
                pr = pr->next;    //指向本行中下一个单词并进行比较
            }
            ps = ps->next;    //对待搜索的下一个单词进行统计
        }
        DestroyWordLink(RL);//销毁已被搜索过的文件中该行单词的链表
    }
}

void OutputSWLinkList(SWLinkList S)    //输出待搜索的单词链表在文本中出现的次数和行号
{
    SWLink p;    //指向待输出的单词
    RowNumLink pr;    //指向待输出单词的某一行
    cout << "搜索结果:" << endl;
    p = S.head->next;
    while (p)
    {
        printf("%-8s", p->data.data);
        cout << "出现的次数" << p->count << "  " << "所在行为:";
        if (p->count)
        {
            pr = p->RNhead;
            while (pr)
            {
                cout << pr->elem << ",";
                pr = pr->next;
            }
            cout << endl;
            p = p->next;
        }
    }
}

void OpenFile(PFILE &f, String ch)    //打开文件,表示文件的路径及名称
{
    if (!(f = fopen(ch, "r")))    //以只读方式打开文件
    {
        cout << "file not open" << endl;
    }
    else
        cout << "file open" << endl;
}

int main()
{
    while (1)
    {

        PFILE f;
        String ch;
        SWLinkList S;
        cout << "*----------------------------------------------------*" << endl;
        cout << "*----------------欢迎使用文学研究助手----------------*" << endl;
        cout << "*                                                    *" << endl;
        cout << "*----------请输入要搜索的文本的路径及文件名:--------*" << endl;
        cin >> ch;
        OpenFile(f, ch);
        CreateSWLinkList(S);
        MatchSWLinkList(S, f);
        OutputSWLinkList(S);
        fclose(f);
        cout << "*----------------------谢谢使用!--------------------*" << endl;
        system("pause");
    }
    return 0;
}


阅读更多

新人开发百度地图,出错了

03-19

package com.example.baidumaptest;rnrnimport android.app.Activity;rnimport android.os.Bundle;rnrnimport com.baidu.mapapi.BMapManager;rnimport com.baidu.mapapi.map.MapView;rnrnrnpublic class MainActivity extends Activity rnprivate BMapManager manager;rnprivate MapView mapView;rn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn rn manager = new BMapManager(this); /*出错Multiple markers at this line- Syntax error on token "BMapManager", rn ( expected after this token- The constructor BMapManager(MainActivity) is undefined*/]rn manager.init("6A9bg3BDnp7XNBhNEm7wzKD8",null); //第一个参数为API Key,rn //出错了The method init() in the type BMapManager is not applicable for the arguments (String, null)rnrn rn setContentView(R.layout.activity_main);rn mapView = (MapView)findViewById(R.id.map_view);rn mapView.setBuiltInZoomControls(true); rn //出错,The method setBuiltInZoomControls(boolean) is undefined for the type MapViewrn rn rn rn@Overridernprotected void onResume() rnmapView.onResume();rnif(manager!=null)rnmanager.start(); //出错rnrnsuper.onResume();rnrn@Overridernprotected void onPause() rnmapView.onPause();rnif(manager!=null)rnmanager.stop(); //出错rnrnsuper.onPause();rnrn@Overridernprotected void onDestroy() rnmapView.onDestroy();rnif(manager!=null)rnmanager.destroy();rnmanager = null;rnrnsuper.onDestroy();rnrnrn rnrnrn出了5个错误,请问怎么解决啊???rn

求助,图书管理系统。C++代码哪里出错了

06-04

[code=C/C++][/code]rnrn#include rn#include rn#include rn#include //输入/输出文件流类rnusing namespace std;rnconst int Maxr=100;//最多的读者rnconst int Maxb=100;//最多的图书rnconst int Maxzf=5;//每位读者最多借五本书rn//读者类,实现对读者的信息的描述rnrnclass Readerrnrn private:rn int tag; //删除标记 1:已删 0:未删rn int no; //读者编号rn char name[10]; //读者姓名rn int zfbook[Maxzf];//所借图书rn public:rn Reader() rn char *getname() return name; //获取姓名rn int gettag() return tag; //获取删除标记rn int getno() return no; //获取读者编号rn void setname(char na[]) //设置姓名rn rn strcpy(name,na);rnrn rn void delbook() tag=1; //设置删除标记 1:已删 0:未删rn void addreader(int n,char *na)//增加读者rn rn tag=0;rn no=n;rn strcpy(name,na);rn for(int i=0;i> choice;rn switch (choice)rn rn case '1':rn cout << "输入读者编号:";rn cin >> readerid;rn cout << "输入读者姓名:";rn cin >> rname;rn addreader (readerid,rname);rn break;rn case '2':rn cout << "输入读者编号:";rn cin >> readerid;rn r=query(readerid);rn if (r==NULL)rn rn cout << " 该读者不存在 "<> rname;rn r->setname(rname);rn break;rn case '3':rn cout << " 输入读者编号:";rn cin >> readerid;rn r=query(readerid);rn if (r==NULL)rn rn cout <<" 该读者不存在" << endl;rn break;rn rn r->delbook();rn break;rn case '4':rn cout << "读入读者编号:";rn cin >> readerid;rn r=query(readerid);rn if (r==NULL)rn rn cout <<"该读者不存在"<< endl;rn break;rn rn r->disp();rn break;rn case '5':rn disp();rn break;rn case '6':rn clear();rn break;rn default:cout<<"输入错误,请从新输入:";break;rn rn rnrnrnrnrn//图书类,实现对图书的描述,图书的编号,书名,借出,还入等rnclass Bookrnrnprivate:rn int tag;//删除标记 1:已删 0:未删rn int no;//图书编号rn char name[20];//书名rn char author[20];//作者rn char cbs[20];//出版社rn double price;//价格rn int onshelf;//是否再架 1:再架 2:已借rnpublic:rn Book()rn char *getname() return name; //获取姓名rn char *getauthor() return author; //获取作者rn char *getcbs() return cbs; //获取出版社rn int getno() return no; //获取图书编号rn double getprice() return price; //获取图书价格rn int gettag() return tag; //获取删除标记rn void setname(char na[])//设置书名rn rn strcpy(name,na);rn rn void setauthor(char au[])//设置作者rn rn strcpy(author,au);rn rn void setcbs(char cbs[])//设置出版社rn rnrn rn void setprice(double price)//设置价格rnrnrn void delbook() tag=1;//删除图书rn void addbook(int n,char *na,char *au,char *cbs,double price)//增加图书rn rn tag=0;rn no=n;rn strcpy(name,na);rn strcpy(author,au);rn double p;rn price=p;rn onshelf=1;rn return;rn rnrn int zfrowbook()//借书操作rn rn if (onshelf==1)rn rn onshelf=0;rn return 1;rn rn return 0;rn rn void retbook()//还书操作rn rn onshelf=1;rn rn void disp()//输出图书rn rn cout << setw(6) << no << setw(18) << name << setw(18) << author<< setw(18) <> choice;rn switch (choice)rn rn case '1':rn cout << "输入图书编号:"<> bookid;rn cout << "输入图书书名:"<> bname;rn cout << "输入作者:"<> bauthor;rn cout << "输入出版社:"<> bcbs;rn cout << "输入图书价格:"<> bprice;rn addbook(n,na,au,cbs,price);rn break;rn case '2':rn cout << "输入图书编号:"<> bookid;rn b=*query(bookid);rn if (b==NULL)rn rn cout << " 该图书不存在 "<> bname;rn b->setname(bname);rnrn cout << "输入新的作者:"<> bauthor;rn b->setauthor(bauthor);rn cout << "输入新的出版社:"<> bcbs;rn b->setcbs(bcbs);rn cout << "输入新的价格:"<> bprice;rn b->setprice(bprice);rn break;rn case '3':rn cout <<" 读入图书编号:"<> bookid;rn b=*query(bookid);rn if (b==NULL)rn rn cout <<" 该图书不存在" << endl;rn break;rn rn b->delbook();rn break;rn case '4':rn cout << " 输入书名:"<> bna;rn int k;rn for ( k=0;k<100;k++)rn if(strcmp(book[k].getname(),bna)==0)rn if(book[k].gettag()==0)rn return ;rn rn rnrnrnrn rn cout <<" 该图书不存在"<< endl;rn break;rn rn b->disp();rn break;rn case '5':rn disp();rn break;rn case '6':rn clear();rn break;rn default:cout<<"输入错误,请从新输入:";rn rn rnrnrn//main() 函数的实现,程序的主界面的引导rnint main()rnrn char choice;rn int bookid,readerid;rn RDatabase ReaderDB;rn Reader *r;rn BDatabase BookDB;rn Book *b;rn while(choice!='0')rn rn cout <> choice;rn switch (choice)rn rn case '1':rn cout <<" 借书 读者编号:";rn cin >>readerid;rn cout <<" 图书编号: ";rn cin >>bookid;rn r=ReaderDB.query(readerid);//按编号查找rn if (NULL==r)rn rn cout <<" 不存在该读者,不能借书"<< endl;rn break;rn rn b=BookDB.query(bookid);rn if (b==NULL)rn rn cout <<" 不存在该图书,不能借书"<< endl;rn break;rn rn if (b->zfrowbook()==0)rn rn cout << " 该图书已借出,不能借书"<< endl;rn break;rn rn r->zfrowbook(b->getno());rn break;rn case '2':rn cout<<"还书\n 读者编号:";rn cin >>readerid;rn cout << " 图书编号:";rn cin >>bookid;rn r=ReaderDB.query(readerid);rn if (r==NULL)rn rn cout <<" 不存在该读者,不能还书" << endl;rn break;rn rn b=BookDB.query(bookid);rn if (b==NULL)rn rn cout <<" 不存在该图书,不能还书" <retbook();rn r->retbook(b->getno());rn break;rn case '3':rn BookDB.bookdata();rn break;rn case '4':rn ReaderDB.readerdata();rn break;rn default:cout<<"输入错误,请从新输入:";rn rn rnrn

代码错了,不明白原因,求助中~

04-18

[code=C/C++]#include rnclass complex rnpublic:rn complex ()rn i=0;rn j=0;rn rn complex(int a, int b)rn i=a;rn j=b;rn rn void print ()rn std::cout << i <<"+" << j << "i" << std::endl;rn rn complex add(const complex &c)rn complex t;rn t.i=i+c.i;rn t.j=j+c.j;rn return t;rn rnprivate:rn int i;rn int j;rn;rnrnint main()rn complex a(4,5);rn complex b(6,7);rn complex c=a.add(b);rn a.print();rn b.print();rn c.print();rn return 0;rnrnrn--------------------Configuration: 2 - Win32 Debug--------------------rnCompiling...rn2.cpprnLinking...rnLIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16rnDebug/2.exe : fatal error LNK1120: 1 unresolved externalsrnError executing link.exe.rn[/code]rnrn2.exe - 2 error(s), 0 warning(s)rnrn请问这个代码为什么会出现error LNK2001rn我查MSDN:rnCode will generate this error message if it references something (like a function, variable, or label) that the linker can’t find in all the libraries and object files it searches. In general, there are two reasons this error occurs: what the code asks for doesn’t exist (the symbol is spelled incorrectly or uses the wrong case, for example), or the code asks for the wrong thing (you are using mixed versions of the libraries?some from one version of the product, others from another version). rn说是请求的不存在或者请求的错误rn上面这个代码是昨天我发帖时别人写给我的,而且我看了,没发现有错误rn请问到底是怎么回事?到底错在哪里?rn谢谢大家了~rn

练习的代码错了

07-26

第一个文件WriteMail.java代码rnimport javax.swing.*;rnimport java.awt.*;rnrnpublic class WriteMail extends JFramernrn WriteMailEvent sendmail=new WriteMailEvent(this);rnrn public WriteMail()rn rn super("Write an E-mail");rn setSize(370,270);rn setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn FlowLayout flow=new FlowLayout(FlowLayout.LEFT);rn setLayout(flow);rn rn JPanel row1=new JPanel();rn JLabel toLabel=new JLabel("To:");rn row1.add(toLabel);rn JTextField to=new JTextField(24);rn row1.add(to);rn add(row1);rnrn JPanel row2=new JPanel();rn JLabel subjectLabel=new JLabel("Subject:");rn row2.add(subjectLabel);rn JTextField subject=new JTextField(24);rn row2.add(subject);rn add(row2);rn rn JPanel row3=new JPanel();rn JLabel messageLabel=new JLabel("Message:");rn row3.add(messageLabel);rn JTextArea message=new JTextArea(4,22);rn message.setLineWrap(true);rn message.setWrapStyleWord(true);rn JScrollPane scroll=new JScrollPane(message,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);rn row3.add(scroll);rn add(row3);rnrn JPanel row4=new JPanel();rn JButton send=new JButton("Send");rn row4.add(send);rn add(row4);rnrn send.addActionListener(sendmail);rnrn rn setVisible(true);rnrn rnrn public static void main(String[] arguments)rn rn WriteMail mail=new WriteMail();rn rnrnrn第二个文件WriteMailEvent.java代码rnimport javax.swing.*;rnimport java.awt.event.*;rnrnpublic class WriteMailEvent implements ItemListener,ActionListener,Runnablernrn WriteMail gui;rn Thread Playing;rn rnrn public WriteMailEvent(WriteMail in)rn rn gui=in;rn rnrn public void actionPerformed(ActionEvent event)rn rn String command=event.getActionCommand();rn if(command=="send") sendPlaying(); rn rnrn void sendPlaying()rn Writern Playing=new Thread(this);rn Playing.start();rn rnrnrn我想实现的是:当按下send按钮时跳出一个文本框提示你发送成功,确认后退出框架,请问如何编写后续代码呢。rnrn 另外我这上面代码有错,说未覆盖监听方法。和WriteMailEvent不是抽象的等等rnrn请高手修改和补充谢谢rn

代码错了,请教

04-10

package com.climatecenter.servlet;rnrnimport java.io.IOException;rnimport java.io.PrintWriter;rnimport java.util.*;rnrnimport javax.servlet.ServletException;rnimport javax.servlet.http.HttpServlet;rnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnrnimport java.sql.*;rnimport com.climatecenter.db.*;rnrnpublic class login extends HttpServlet rn static Random rand = new Random();rn static String[] getPar = new String[rand.nextInt()];rnrn public void doGet(HttpServletRequest request, HttpServletResponse response)rn throws ServletException, IOException rn response.setContentType("text/html");rn PrintWriter out = response.getWriter();rn Enumeration parameterNames = request.getParameterNames();rn ......rnrn while (parameterNames.hasMoreElements()) rn String parameterName = (String) parameterNames.nextElement();rn String[] tempPar = request.getParameterValues(parameterName);rnrn for (int i = 0; i < tempPar.length; i++)rn if (tempPar[i] != null)rn getPar[i] = tempPar[i];rn elsern System.out.println("空");rn ......rnrnrn我是新手,请问我的代码出错在哪里呢?rn报错信息如下:rnjavax.servlet.ServletException: Error instantiating servlet class com.climatecenter.servlet.loginrn org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn java.lang.Thread.run(Unknown Source)rn

[新人]jsp:mysql+tomcat5连接出错了,

05-14

出错提示:rnjavax.servlet.ServletException: org/aspectj/lang/Signaturern org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)rn org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)rn org.apache.jsp.admin.Admin_005fsys_005fclass_jsp._jspService(org.apache.jsp.admin.Admin_005fsys_005fclass_jsp:80)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrnrnroot cause rnrnjava.lang.NoClassDefFoundError: org/aspectj/lang/Signaturern java.lang.Class.forName0(Native Method)rn java.lang.Class.forName(Unknown Source)rn com.cjy.DBMysqlConn.getConnection(DBMysqlConn.java:55)rn com.cjy.DBMysqlManager.(DBMysqlManager.java:15)rn org.apache.jsp.admin.Admin_005fsys_005fclass_jsp._jspService(org.apache.jsp.admin.Admin_005fsys_005fclass_jsp:57)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn=====================================rnjsp页面:rn<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>rn<%@ page import="java.sql.*" %>rn<% String path = request.getContextPath();rn String basePath = request.getScheme()+"://"+rn request.getServerName()+":"rn +request.getServerPort()+path+"/";rn String title = "";rn%>rnrnrnrn rn <%=title%>rn rnrnrnrnrnrnrn=======================================rn类页面:rn//程序名称:DBMysqlConnrn//程序目的:建立数据库的链接rnpackage com.cjy;rnimport java.sql.*;rnrnpublic class DBMysqlConnrn rn // driverName为驱动器类型的名称rn // url为连接字符串rnrn private String driverName = "com.mysql.jdbc.Driver";rn private String url = "jdbc:mysql://localhost/cjy";rn rn private String user = "sa";rn private String password = "";rn Connection conn = null;rn rn public String getDriverName()rn rn return driverName;rn rn public void setDriverName(String driverName)rn rn this.driverName=driverName;rn rn public String getUrl()rn rn return url;rn rn public void setUrl(String url)rn rn this.url=url;rn rn rn public String getPassword()rn rn return password;rn rn public void setPassword(String password)rn rn this.password=password;rn rn public String getUser()rn return user;rn rn public void setUser(String user)rn rn this.user=user;rn rn rn public Connection getConnection()rn rn tryrn rn Class.forName(driverName).newInstance();// 加载驱动器rn conn=DriverManager.getConnection(url, user, password);//连接到数据库.rn rn catch (Exception e)rn rn e.printStackTrace();rn conn=null;rn rn return conn;rn rnrn2:;;;;;;;;;;;;;;;;;;;;rn//DBMysqlManager,javarn//数据操作 rnpackage com.cjy;rnimport java.sql.*;rnrnpublic class DBMysqlManagerrn private Connection conn = null; // Connection对象rn private Statement stmt = null; // Statement对象rn private ResultSet rs = null; // 记录结果集rn private String sqlstr; // sql语句rn private boolean isConnect;//状态rn public DBMysqlManager()rn tryrn DBMysqlConn dcm = new DBMysqlConn();rn conn = dcm.getConnection();//连接到数据库的rn stmt = conn.createStatement();//创建一个sql语句。rn rn catch (Exception e)rn rn System.out.println("连接失败"+e);rn isConnect=false;rn rn rn public Connection getConn()rn rn return conn;rn rnrn public Statement getStmt()rn rn return stmt; //用statement声明一个sql语句对象,rn //然后通过创建的数据库对象conn调用createStatement()方法创建sql语句对象。rn rnrn public ResultSet getRs()rn rn return rs;rn rn public ResultSet executeQuery(String sqlstr)//查询记录rn rn tryrn rn rs = stmt.executeQuery(sqlstr);rn return rs;rn rn catch(SQLException e)rn rn System.out.println("连接失败!"+e.toString());rn return null;rn rn catch(NullPointerException e) rn rn System.out.println("数据库连接失败!"+e.toString());rn return null;rn rn rn public int executeUpdate(String sqlstr) throws Exception//修改、删除、插入记录rn rn int i=stmt.executeUpdate(sqlstr);rn close();rn return i;rn rn rn rn public void close() throws SQLExceptionrn rn if (rs != null)rn rn rs.close();rn rs = null;rn rn if (stmt != null)rn rn stmt.close();rn stmt = null;rn rn if (conn != null)rn rn conn.close();rn conn = null;rn rn rnrnrnrn请问那个出错了

没有更多推荐了,返回首页