ok i need to write an experimental applet code for a student information searcher. THis is what i have, and it sucks. it doesnt work so if anyone can set me inteh right direction....much appreciated.....ty in advance
i don't know about anyone else, but that code is a little unreadable (opened in notepad). Maybe you would be better copying and pasting it into here using the [ CODE ] and [ /CODE ] tags (no spaces though obviously).
thanx buddy,i know it does. btw i am using an MsAccess db right now (ehhhh) and i would like to change the db type if possible....maybe someone here knows the best kind to use. Also, the mdb is JAVAPROG.mdb if someone could give me suggestions/fix my code it would be very kind.
when using the bridge driver, you must set up an ODBC data connection to the database , using the Data Sources (ODBC) control panel. have you done this?
remember, the BRIDGE is just that.. it joins 2 points.. the JDBC riverbank side and the ODBC riverbank side..
only thing is, you havent built the ODBC riverbank yet.. and nothing you can put in a java program, short of some JNI (java native interface) wizardry, can do it.
you must use the Data Sources (ODBC) control panel to set up a User DSN (data source name)...
on this line:
Code:
url = "jdbcdbc:JAVAPROG";
the following elements are present:
Code:
DRIVERPATH:DATASOURCENAMEjdbc:odbc:JAVAPROG
the driverpath tells the driver manager which driver to use. the data source name specifies where the information comes from.. are you seeing it yet? you wrote JAVAPROG, but what does that mean? where did you actually link the logical name JAVAPROG to an MS access database? :)
if u are refering to the JAVAPROG.mdb that resides in the program directory taht i created using the Control Panel > Administrative Tools > Data Sources(ODBC) > User Dsn tab...........then yes, i have created one......... should i say
Code:
jdbc:odbc:JAVAPROG.mdb
?
I did set up a user DSN using the path i specified above...i just cant get my applet to query the database and display the information in the respective fields...would you like me to attach the html file? Im completely stumped as to how I can get my program to successfully query my DB and then take the results from that query and display it.......as far as my simply educated java mind can tell....my program is correct...it no longer gives me the driver error i used to get in my connections field...however after i hit search, nothing happens. I was under the impression that my code would query the DB using SQL syntax in the form of a String, then return the information from the table "info" (that exists in JAVAPROG.mdb) with columns "Fname" "Lname" etc... and (for now) 2 rows; one containing my information for each field and another containing my friends information. Does an MDB use different syntax than SQL does, for example, i query w/
Code:
SELECT Name FROM info WHERE Name = 'Max'
does an MDB use something like
Code:
SELECT FROM info WHERE Name = 'Max'
or something? Im really confused. Am i just retarded and my code is what is wrong? Ty for all your time and knowledge btw cjard i really appreciate it. =)
If you created the database with the ODBC control panel, then made sure you gave it a data source name, and pressed ok, yyou should see JAVAPROG appear in the list of User DSNs
thats all that is needed.. you then use the following url to connect:
jdbc:odbc:JAVAPROG
-
answers come back froma database via an object called a ResultSet:
Code:
ResultSet rs = myStatement.executeQuery("SELECT * FROM tblMyTable WHERE name = 'John' AND age = 22")
//RSMD provides information about the data, i.e. number of columns etc
ResultSetMetaData rsmd = rs.getMetaData();
the resultset is a forward only (unless otherwiese specified) data crawler. It has a method, next(), that returns false when there are no more rows:
Code:
while(rs.next()){
//first column is 1 not 0 !!!!
System.out.println(rs.getString(1));
System.out.println(rs.getInt(2));
System.out.println(rs.getString("name"));
System.out.println(rs.getInt("age"));
}
you can call getXXX as many times as you want per row, but when you call next() the rs moves on to the next row... and that's it!
so, get your strings, and then add() them to a JTable..