Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 186c602

Browse files
author
Chris Board
committed
Fixed formatting in README.md
1 parent aa96f9f commit 186c602

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ MeriaDB and MySQL version should be compatible and therefore should work in the
3232

3333
# Adding Dependency
3434
Adding the library to your project couldn't be simpler. Add the following to your apps build.gradle
35-
'''
35+
```
3636
repositories {
3737
maven { url 'https://jitpack.io' }
3838
}
3939
4040
dependencies {
4141
implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:TAG'
4242
}
43-
'''
43+
```
4444

4545
The `TAG` above will be the tagged version number of the library.
4646

@@ -54,9 +54,9 @@ or constructor will take an interface which will get called once the action has
5454

5555
## Connecting to a MySQL Server
5656
To connect to a MySQL server you first need to create the MySQL Connection object. You can do this as follows:
57-
'''
57+
```
5858
Connection mysqlConnection = new Connection("<Hostname>", "<Username>", "<Password>", <Port>, "<Database>", new IConnectionInterface()
59-
'''
59+
```
6060

6161
In the above example, <database> is an optional parameter. By setting this, when the connection is established, the database name will be the default
6262
database used. The IConnectionInterface parameter handles connection specific events, such as successfully connected or exception handlers.
@@ -97,14 +97,14 @@ you will receive a call back to the actionCompleted method.
9797
## Execute Statement (Such as INSERT or UPDATE where no resultset is returned)
9898
First of all you need to create a statement object from your connection object.
9999
You can do this using the following code snippet
100-
'''
100+
```
101101
Statement statement = connection.createStatement();
102-
'''
102+
```
103103

104104
Then in order to execute your statement you then do the following
105-
'''
105+
```
106106
statement.execute(query, new IConnectionInterface());
107-
'''
107+
```
108108

109109
`query` is your statement that you want to execute such as an INSERT or UPDATE statement. Again the second
110110
parameter is the IConnectionInterface and if the statement execute successfully, then actionCompleted will be called.
@@ -113,15 +113,15 @@ parameter is the IConnectionInterface and if the statement execute successfully,
113113
The execute query function allows you to execute a query such as SELECT or DESCRIBE, basically any query
114114
which return a result set. Same with executing a statement, you need to create the statement object from your
115115
connection object. This can be done using the following code snippet:
116-
'''
116+
```
117117
Statement statement = connection.createStatement();
118-
'''
118+
```
119119

120120
Then you need to call the executeQuery withn your statement object, but this time passing in a new
121121
IResultInterface as shown below:
122-
'''
122+
```
123123
statement.executeQuery(query, new IResultInterface());
124-
'''
124+
```
125125

126126
The IResultInterface is pretty similar to the IConnectionInterface, you'll have the same exception handlers,
127127
the main difference that if the query executes successfully, you'll receive executionComplete which will have
@@ -137,9 +137,9 @@ To get the total number of rows you can call `resultset.getNumRows();`.
137137
## Get column definitions
138138
The column definitions are stored in a `List<ColumnDefinition>`. You can get this using the following code snipper:
139139

140-
'''
140+
```
141141
List<ColumnDefinition> columns = result.getFields();
142-
'''
142+
```
143143

144144
You can then loop over the list to get ColumnDefinition for each column returned in the result set. Within the column
145145
definition class, you can use the following methods:
@@ -163,13 +163,13 @@ You can iterate through each row, you first need to create an empty `MySQLRow` v
163163
to be set within a while loop to get each row. You can call `getNextRow()` on the result set to get a MySQLRow.
164164
Once there are no rows left, null is returned. The following code snippet provides an example:
165165

166-
'''
166+
```
167167
MySQLRow row;
168168
while ((row = result.getNextRow()) != null)
169169
{
170170
//Read the row contents here
171171
}
172-
'''
172+
```
173173

174174
Once you have your MySQLRow you can then call the following methods to return the value of the field.
175175
Each of the following methods, take a String parameter which is the column name that should be retrieved.
@@ -182,9 +182,9 @@ Each of the following methods, take a String parameter which is the column name
182182
When sending dynamic paraters in your MySQL query, the string should be escaped to avoid SQL injection attacks.
183183
This can be done by using the following code snippet:
184184

185-
'''
185+
```
186186
String var = connection.escape_string(variable);
187-
'''
187+
```
188188

189189
# Best Practices
190190
Currently the connection object can't be passed between Android activities, so if you do need to create a new Activity

0 commit comments

Comments
 (0)