Click here to Skip to main content
13,052,342 members (54,496 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello everyone.
I have a problem I have searched too much but I can't solve this. I am using netbeans and I have an oracle database. This is my first time to connect an application with a database. Simply, I have a form at netbeans and a table at database.[^] In here I have 2 textboxes and a combobox whic has 2 items (administrator and instructor). I want to code under the add button. Namely, I want to save user name password and its role in a table. Here I have created a table.[^]

I am noob guys, please help me. If you teach me how to insert I will develop delete update etc.

//UPDATE// here is my button code

try {
      Connection con=null;
        "jdbc:oracle:thin:@AND ALSO HERE:1521:O10G",
      Statement s=con.createStatement();
 catch(ClassNotFoundException | SQLException e){}

Posted 31-Jul-12 20:49pm
Updated 31-Jul-12 21:15pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First setup a connection to your database.
Before trying to actually access the database from your program, try to connect to it using sqlplus from your development machine. This way you know that the connection string and tnsnames.ora is correct.
There is tons of information about this on the web.[^]

Then when it comes to inserting here is another link :[^]

Also here there is a ton of information on the web.
TuranEmre 1-Aug-12 3:13am
Thanks Philip as I mentioned I have searched a lot but something is wrong. Here is my button code. (Updated into question)
Philip Stuyck 1-Aug-12 3:30am
Your insert statement should be something like this :
insert into e_user values('bla','bla','bla')
Like the second example I posted you have to assemble the string dynamically. There are other ways using parameters but this is a little more advanced.
I really think that with this last link I provided it should help you get this working.
TuranEmre 1-Aug-12 3:40am
Yes I see but how could I send textboxes? insert into e_user values('bla','bla','bla') this is easy I want to solve this
s.execute("INSERT INTO E_USER VALUES(((u_name,u_pass,u_role)('"+txtAddUserName.getText()+"','"+txtAddUserPassWord.getText()+"','"+cmbAddUserRole.getSelectedItem().toString()+"')");
Philip Stuyck 1-Aug-12 4:03am
your insert statement looks wrong to me since you are specifying the column names in the values.
Look at this :
bottom line is
(first_name, last_name)
('john', 'smith');
Philip Stuyck 1-Aug-12 4:08am
As a general tip. Try out your insert statement manually first. If you can insert it manually in the database, that sql statement is the one you need to create by code. You can also use a temp string variable and print it or debug it to see what is actually the string you are using for your insert.
TuranEmre 1-Aug-12 10:32am
Philip you don't understand neither me nor my question. This is an Form application. Instead of john I have to use txtAddUserName.getText(). Because It may be john Philip or Turan. What the user wants? I tried it manually it works with static names but I need to use it dynamically via textbox.
Philip Stuyck 1-Aug-12 11:02am
don't you see that your string that you are passing in s.execute is completely wrong ?
You are doing something like INSERT INTO E_USER VALUES(((u_name,u_pass,u_role)('bla','bla','bla'))) This is just plain wrong SQL syntax.
It should be more like
s.execute("INSERT INTO E_USER(u_name,u_pass,u_role) VALUES('"+txtAddUserName.getText()+"','"+txtAddUserPassWord.getText()+"','"+cmbAddUserRole.getSelectedItem().toString()+"')");
or not mention the column names at all.
s.execute("INSERT INTO E_USER VALUES('"+txtAddUserName.getText()+"','"+txtAddUserPassWord.getText()+"','"+cmbAddUserRole.getSelectedItem().toString()+"')");
will also work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100